Professional Documents
Culture Documents
Public Class Public Static New True True: Status Out Println Numberofstudents
Public Class Public Static New True True: Status Out Println Numberofstudents
Third, I use "super" as a variable by calling the static variable of the class
"super.numberOfStudents". This is also very useful because we might have another variable
with the same name. By putting "super" in the frond we make clear that we want to access the
class level variable.
OUTPUT:
Age: 18
Sex: Male
Number of Students: 1
Finally, in the example below I use "this" as a constructor. This is also a very useful tool
because we can call the constructor with no parameters while we are in another constructor of
the same class.
public class Example2 {
1
String name;
2
Example2(){
3
System.out.println("Welcome!");
4
}
5
Example2(String name){
6
this();
7
this.name=name;
8
System.out.println("Your name is "+ name);
9
}
10
11
public static void main(String[] args){
12
Example2 example=new Example2("Chris");
13
14
}
15
}
16
OUTPUT:
Welcome!