update,
This commit is contained in:
7
_resources/it114105/itp3914/Lab11/Ex8/Ex8.java
Normal file
7
_resources/it114105/itp3914/Lab11/Ex8/Ex8.java
Normal file
@@ -0,0 +1,7 @@
|
||||
public class Ex8 {
|
||||
public static void main(String[] args) {
|
||||
Student stu1 = new Student("John Chan"); //line 10
|
||||
System.out.println(Student.numberOfStudent); //line 11
|
||||
System.out.println(stu1.name); //line 12
|
||||
}
|
||||
}
|
17
_resources/it114105/itp3914/Lab11/Ex8/Student.java
Normal file
17
_resources/it114105/itp3914/Lab11/Ex8/Student.java
Normal file
@@ -0,0 +1,17 @@
|
||||
public class Student {
|
||||
public static int numberOfStudent=0; //line 1
|
||||
public String name; //line 2
|
||||
|
||||
public Student (String name) { //line 3
|
||||
numberOfStudent++ ; //line 4
|
||||
setName(name); //line 5
|
||||
}
|
||||
|
||||
public int getNumberOfStudent() { //line 6
|
||||
return numberOfStudent; //line 7
|
||||
}
|
||||
|
||||
public void setName(String name) { //line 8
|
||||
this.name = name; //line 9
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user