Static is a non-access modifier used in java, applicable for methods, variables, class. When the static keyword is used to declare any parameter, then memory is allocated only once for that parameter.
class Employee{
int id;
String name;
static String company = "WIT";
static void change(){
company = "SRT";
}
Employee(int i, String n){
id = r;
name = n;
}
void display (){System.out.println(id+" "+name+" "+company);}
public static void main(String args[]){
Employee.change();
Employee e1 = new Employee (111,"John");
Employee e2 = new Employee (123,"Alex");
e1.display();
e2.display();
}
}
Output of this code will be:
111 John SRT
123 Alex SRT
Hope it helps!!
If not then its recommended to join our Java training class and learn about Java in detail.
Thank You!!