• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between Instance, Object and reference

 
Atul Sawant
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please let us know what is the difference between object, instance and reference?
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Naina Si
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object is an instance of a Class. You can create many instances of a class (Objects of that particular Class type)

You can refer to objects using references.
 
Karun Subramanian
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !

Object = Instance of a Class.
Instance = Object
Reference = A variable that holds bit patern which points to the Object in the Memory (Heap).

Example:

public class Car {
int year;
String make;
public static void main(String[] args) {
Car mycar = new Car(); // Create a Car object.
// Here mycar = Reference variable that points to the Object of type Car
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic