OOP · Core Java OOP Features
static Keyword
Imagine a College Management System where every student belongs to the same college.
Uses of super
- Access parent class variables
- Invoke parent class methods
- Invoke parent class constructors
Real-World Problem
Imagine a College Management System where every student belongs to the same college. Storing the college name separately in every object wastes memory. Why Do We Need static?

The static keyword allows data or methods to belong to the class instead of individual objects. This helps save memory and enables members to be shared by all objects. What is static? The static keyword is used to create class-level members that are shared among all objects of a class.
Types of Static Members
Static Variable Stores data common to all objects.
Static Method Can be called without creating an object.
Static Block Executes once when the class is loaded into memory.
Static Nested Class A nested class declared with the static keyword that can be accessed without creating an object of the outer class.
Utility Class A class that contains only static methods and variables to provide common utility functions
static members belong to the class itself, shared across every instance.
public class Employee {
static int count = 0; // one shared value for all Employees
int id; // per-object
Employee() {
id = ++count; // increments the shared counter
}
static int headcount() { // callable without an instance
return count;
}
public static void main(String[] args) {
new Employee();
new Employee();
System.out.println(Employee.headcount()); // 2
}
}