Instance Members#
Non-static members that are termed instance members are not directly accessible from static members. They are required to be qualified through an object. The static methods can be called without the object. The keyword this
is also not accessible from the static methods so attempting to qualify an instance member with this
will fail in those methods.
Polymorphism#
Polymorphism is a powerful feature of the object-oriented programming (OOP) paradigm. It provides the facility of calling the correct version of the method depending on the instance held by the base reference. It means we can call an overridden version of a base class method in its derived class using a derived instance through a base reference.
The static methods are class-level operations therefore they cannot be overridden. It’s not a weakness of Java; it’s the technically correct implementation. The static methods do not carry an implicit reference to the calling object (through this
) therefore they cannot implicitly trace the type of calling object.
Memory Matters#
Static members are class-level features. They are provided as shared facilities for all instances of the class. Their construction and destruction are not bound to the life of any object. They are allocated in the memory at the start of the execution of the program or at the time of loading of the class. They are not garbage collected; therefore, they stay in the memory till the end of the program. We need to be more cautious about memory leaks due to the same reason.