wht is the class and object wht is difference between two ? I have read lots of defination but still am not clear.... i need some realistic example please advise

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

answered by (171 points)
0 votes

Okay. Class is stucture. Say.

class a{

variable a;

variable b;




Above is class. When you use new keyword, JVM (Java Virtual Machine) will allocate memory for above structure in RAM(Random Access Memory). That allocated memory is called Object.



a A = new a();


where A is another variable of tyep class "a", which we have defined above.

a(); is default constructor of class, so when you say new a(); JVM will allocate memory for class a, which you call it as object.

And as you know every memory has reference, so that reference will be stored into variable A.

Hope it makes clear now.


Class is structure consist of variables and methods.

Object is memory allocated to structure by JVM.