-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentDriver.java
More file actions
67 lines (55 loc) · 1.41 KB
/
StudentDriver.java
File metadata and controls
67 lines (55 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class Student {
private int rollNo;
private String name;
Student() {
rollNo = -1;
name = "New Student";
}
Student(int rollNo) {
this.rollNo = rollNo;
name = "New Student";
}
Student(String name) {
rollNo = -1;
this.name = name;
}
Student(String name, int rollNo) {
this.name = name;
this.rollNo = rollNo;
}
Student(int rollNo, String name) {
this.rollNo = rollNo;
this.name = name;
}
public void setRollNo(int rollNo) {
this.rollNo = rollNo;
}
public int getRollNo() {
return this.rollNo;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
protected void display() {
System.out.println("Name : " + this.name + ", RollNo : " + this.rollNo);
}
}
public class StudentDriver {
public static void main(String[] args) {
Student s1 = new Student();
Student s2 = new Student("Bheru", 1);
Student s3 = new Student(2, "Yusuf");
Student s4 = new Student(3);
Student s5 = new Student("Dev");
s1.display();
System.out.println("Name of s2 : " + s2.getName());
System.out.println("Roll No of s3 : " + s3.getRollNo());
s4.setName("Mrid");
s4.display();
s5.setRollNo(4);
s5.display();
}
}