Object and instance in java

I just want to ask that if i have a class A,and i write

1. A sup;
2.A sup=new A();

Then just tell whether I am correct or not,According to me ,the first line indicates that there is a reference variable sup which is allocated in memory,and it is having value null.
And if I talk about 2 line then there is a creation of object and its reference value would be given to reference variable sup,so actually what is instance,as it is said that "an object is an instance of class",so is it that the line new A();is representing an object and instance both or is there some marginal difference between them.

Replies

  • micheal john
    micheal john
    I think you got confused between the terms, both object and instance means same.
  • simplycoder
    simplycoder
    #-Link-Snipped-#

    Nice explanation, worth a read.
  • radha gogia
    radha gogia
    micheal john
    I think you got confused between the terms, both object and instance means same.
    Actually i studied the stack-overflow discussion,in that i read that the reference variable is actually called an instance ,plz clarify it through an example.
  • Anoop Kumar
    Anoop Kumar
    Object: A real memory address which exists.

    Instance: A reference which points to an object.

    Variable xyz is an instance of class Integer.
  • radha gogia
    radha gogia
    Anoop Kumar
    Object: A real memory address which exists.

    Instance: A reference which points to an object.

    Variable xyz is an instance of class Integer.
    Okay,but then why object is called the instance of class when they both are different.
  • Anoop Kumar
    Anoop Kumar
    Actually they both are same it just a way to say this.
    Let see below things in different way.

    Creating a new object.
    Instanciate a class.

    Generally when we create first object of a class we say instanciating it.
  • radha gogia
    radha gogia
    Anoop Kumar
    Actually they both are same it just a way to say this.
    Let see below things in different way.

    Creating a new object.
    Instanciate a class.

    Generally when we create first object of a class we say instanciating it.
    Okay I understood,but do you agree than that the memory location of both the instance and the object are same,since the instance is actually a reference and hence it is allocated in the stack while the object is actually allocated in the heap,elsewise an instance actually means that at a particular instant the creation of object with some particular atrributes of class,so am i rght or nt???
  • Anoop Kumar
    Anoop Kumar
    They both are synonym....
    If you are talking about reference variables then.
    Objects goes in Object heap and variables goes in stack..
    #-Link-Snipped-#
  • radha gogia
    radha gogia
    Anoop Kumar
    They both are synonym....
    If you are talking about reference variables then.
    Objects goes in Object heap and variables goes in stack..
    #-Link-Snipped-#
    Okay, but when i write class obi=new class(),so here obi is the instance or we can say that it is a reference variable so it will obviously go to stack then that means object and instance have both different memory locations or not..
  • Anoop Kumar
    Anoop Kumar
    If they are synonym, we use either of them as per convenience just for notion.
    There is no difference in memory allocation.

You are reading an archived discussion.

Related Posts

At a time when research firm Gartner has released less than average growth figures for tablets in the current year, Lava is making efforts to make Android tablets cool again...
Sorry to have put it this way, but since I have joined, I have seen too little engineering related talk and far too much general product reviews and other talk....
Hello CEans, Life is so much F***ed up! Long-time i never posted any valuable post. All emotional posts. No use. Hope you will find this post helpful. Let's Get Started!...
Google proudly unveiled the Nexus 6, the latest flagship smartphone built by Motorola in a blog post today. The Nexus 6 is a significant improvement from the LG made Nexus...
After making a mark for itself in the tablet world with the critically acclaimed Nexus 7 tablet, Google has announced a bigger offering in form of the Nexus 9. The...