Java - Static Keyword
Consider this Java class:
What will be the output when running
class Employee {
static int employeeCount = 0;
String name;
Employee(String name) {
this.name = name;
employeeCount++;
}
static void printCount() {
System.out.println("Total employees: " + employeeCount);
}
}
public class Main {
public static void main(String[] args) {
Employee e1 = new Employee("Alice");
Employee e2 = new Employee("Bob");
e1.printCount();
Employee.printCount();
}
}What will be the output when running
Main?