-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
52 lines (39 loc) · 1.05 KB
/
Student.java
File metadata and controls
52 lines (39 loc) · 1.05 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
package spec;
public class Student {
protected String rollNumber;
protected String name;
//Constructor to add default values
public Student() {
this.rollNumber = "N/A";
this.name = "N/A";
}
public Student(String rollNumber, String name) {
this.rollNumber = rollNumber;
this.name = name;
}
public Student(String rollNumber) {
this.rollNumber = rollNumber;
this.name = "N/A";
}
//GETTER and SETTER for rollNumber
public String getRollNumber() {
return this.rollNumber;
}
public void setRollNumber(String rollNumber) {
this.rollNumber = rollNumber;
}
//GETTER and SETTER for name
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public void displayData() {
System.out.println("Roll Number: " + this.rollNumber);
System.out.println("Name: " + this.name);
}
public void displayData(String rno) {
System.out.println("The name of student with roll number " + this.rollNumber + " is " + this.name);
}
}