Discussions

Web tier: servlets, JSP, Web frameworks: What is the Difference between instance and object

  1. 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..
  2. Object is an instance of a class[ Go to top ]

    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.