Advanced class features
1) Static variables & methods
2) Nested class
Static variable
Static method
Test class (driver class) – what is the output?
public class TestStudent
{ public static void main(String[] args) {
Student stud1 = new Student(“Ali”, 23);
Student stud2 = new Student(“Abu”, 20); // Instantiate 3 Student objects
Student stud3 = new Student(“Aini”, 18);
[Link](stud1);
[Link](stud2); // calling implicit toString()
[Link](stud3);
[Link]( “Each student need to pay RM”+ [Link]()+ “athletic fee”);
} //end class
Output
display once only!
So what is static variable ?
Why and when you need it ?
Your Answer: