How does a class actually function in java?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How does a class actually function in java??

Like in c++, we need to create an object of the class, but it's not the case in Java, so how does it functions on the basic level.

9th Apr 2018, 4:21 PM
Vaishali Tiwari
Vaishali Tiwari - avatar
1 Answer
+ 8
If you create objects, every object and the fields/methods have it's own space in memory and the reference to the object is stored in the variable that holds the object (like a pointer in c++, but more like a hidden pointer). So you will find objecta.somefield and objectb.somefield of the same class in memory. A static field/method of a class has only one address/space in memory, which is referenced by the class (reflection). You'll find the differences between static and dynamic references on this site: https://www.sitesbay.com/java/java-static-and-non-static-method
9th Apr 2018, 5:15 PM
Tashi N
Tashi N - avatar