Java masks pointers used by basic memory management, so you usually don't need to worry about them. But let's align some terms.
Java class is a plan; it defines behavior (methods) and state (variables). Some parts of the object, in particular those that are static, share all instances of this class (working in the same runtime) and do not even require that the class to be created be accessible to everyone.
An object is a special instance of a class. All non-static variables and methods are unique to this object and only this object. When you use a new one, you instantiate a new class object.
This becomes apparent when you consider how static methods execute differently than non-static methods:
MyObject.aStaticMethod();
Note in the above example, the obj
token is a link (which is different from a pointer) to a specific place in memory. This memory location is an instance of obj
and includes references to code variables and states that are stored in another memory location allocated for the MyObject
class. In this second area, all static and static variables are saved. But usually you donβt need to worry about this level of subtle details.
source share