Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
181 views
in Programming by
recategorized by
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

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)

Okay. Class is stucture. Say.

class a{

variable a;

variable b;

method1();

method2();

}

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.

 

Say

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.

Conclusion:

Class is structure consist of variables and methods.

Object is memory allocated to structure by JVM.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...