Saturday, 8 April 2017

Static Members (Static Methods )

Static Members (Methods, Variables, Static Block and Class)

Static Method


In JAVA, Variables can be declared with the "static" keyword.

Syntax: <class-name>.<method-name>
Example: Student.getName();

A static method can only call only other static methods, i.e. they cannot call a non-static method from it.

A static method can be accessed directly by the class name and doesn’t need any object to all it.

A static method cannot refer to this or super keywords in anyway.

A static method can access only static data. It can not access non-static data (instance variables)

No comments:

Post a Comment