Hi,
I heared the question from my friend. I think instance and object are same with respect to class. but when it will be treated as Different, In which scenarios it will be classified like instance and object..Can anyone tell me what is the exact difference between the instance and object..
Discussions
Web tier: servlets, JSP, Web frameworks: What is the Difference between instance and object
-
What is the Difference between instance and object (1 messages)
- Posted by: kiran annamreddy
- Posted on: September 02 2004 07:26 EDT
Threaded Messages (1)
- Object is an instance of a class by Michael Maruffi on September 03 2004 11:47 EDT
-
Object is an instance of a class[ Go to top ]
- Posted by: Michael Maruffi
- Posted on: September 03 2004 11:47 EDT
- in response to kiran annamreddy
An object and an instance are one in the same. The difference is between classes and objects.
Anything that is static in a class becomes propery of the class itself. These are things like static variables and static methods.
To use things that belong to the class itself, no instance of that class is required. No object is required.
Objects, on the other hand, are instances of a class. Any non static method defined in a class requires an instance for it to be used.
An example of a method that belongs to a class is the Collections.sort() method. This can be invoked simply by using the actual class.
However, adding an object to a LinkedList actually requires an instance of that class to be created.
So in short, an object is an instance of a class, so objects and instances are the same thing.