Results 1 to 6 of 6

Thread: What is the difference between an object and an instance in java?

  1. #1
    Join Date
    Feb 2009
    Posts
    8

    What is the difference between an object and an instance in java?

    Hi,

    What is the difference between an object and an instance in JAVA?

  2. #2
    Join Date
    Jan 2009
    Posts
    44

    Re: What is the difference between an object and an instance in JAVA?

    object has a memory allocated to it during its creation using the syntax
    Code:
    classname var=new classname();
    But for instance creation it returns only a pointer refering to an object,syntax is
    Code:
    classname varname;

  3. #3
    Join Date
    Apr 2008
    Posts
    2,010

    Re: What is the difference between an object and an instance in JAVA?

    Instance in java...

    An actual object of a particular class. An instance of a class is created using the new operator followed by the class name.

    Object in java...

    When we define a class that does not extend any other class, it implicitly extends java.lang.Object. Also, an anonymous class based on an interface.

    In general we think instance and objects are same, but they are incorrect.

    instance will have the both class definiation and the object defination where as in object it will have only the object defination.

  4. #4
    Join Date
    May 2008
    Posts
    2,302

    Re: What is the difference between an object and an instance in JAVA?

    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.

  5. #5
    Join Date
    May 2008
    Posts
    2,393

    Re: What is the difference between an object and an instance in JAVA?

    Objects are key to understanding object-oriented technology.

    Instance Method is a subroutine or function designed to work on the current object. Methods are always part of some class.
    An instance method has access to all the instance variables, other instance methods, as well as the static class-as-a-whole methods and variables.

  6. #6
    Join Date
    May 2008
    Posts
    2,015

    Re: What is the difference between an object and an instance in JAVA?

    The main difference between abstract class and interface is,

    1. Abstract class has the constructor, but interface doesn't have.

    2. Main reason is abstract class contain the instance variable, that why it has
    the constructor, where as interface has only constants (final variables and
    ABSTRACT METHODS).

    3. A class which can implement the interface, is not implement all methods which
    are declared in interface , such class is declared as abstract class. that mean
    abstract class is a subtype of an interface.

    This is my conclusion. If you have an queries let me know.

Similar Threads

  1. About instance variables in java
    By Khaled11 in forum Software Development
    Replies: 1
    Last Post: 19-03-2010, 02:38 PM
  2. Differentiation between C++ object and instance
    By Ram Bharose in forum Software Development
    Replies: 4
    Last Post: 06-02-2010, 12:40 PM
  3. What is Instance variables in Java?
    By Owen Fernandes in forum Software Development
    Replies: 5
    Last Post: 23-01-2010, 07:27 AM
  4. Object reference not set to an instance of an object
    By KAIRU26 in forum Software Development
    Replies: 3
    Last Post: 05-09-2009, 08:14 PM
  5. Object test = new Object() <-- Java, best way in C++
    By ADISH in forum Software Development
    Replies: 3
    Last Post: 25-10-2008, 02:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •