Static Methods and Fields
Static Methods and Fields
Object-Oriented Programming
Static Methods and Fields
static
}
Example of static method
Return type
Static modifier
} Method name
Method body
Example of static method with access
modifier Return type
Static modifier
} Method name
Method body
Access modifier
//in between access modifier and return type ✔
//before the access modifier
✔
//before (or even after) the method name
✖
Example of static field variables
✔
✔
//package-default static variable
✔
//between access modifier and return type
//MyClass.java
//YourClass.java
//constructor
Demonstration
Output
Demonstration
Output
Demonstration
Output
Demonstration
Output