Static Methods

A static method belongs to the class rather than to any specific instance of the class. Static methods can be called without creating an object of the class.

Key Points about Static Methods:

  • They can be called without creating an instance of the class.
  • They can only access static variables and static methods directly.
  • They cannot access instance variables or instance methods directly.
Code Example
Output
This is a static method.