-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTut17.java
More file actions
47 lines (36 loc) · 967 Bytes
/
Tut17.java
File metadata and controls
47 lines (36 loc) · 967 Bytes
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
package tutorial;
//constructor in java
class StudentRecord {
private int rollno;
private String name;
private int std;
// creating the constructor
public StudentRecord(int rollno, String name) {
this.rollno = rollno;
this.name = name;
}
// constructor overloading
public StudentRecord(int rollno, String name, int std) {
this.rollno = rollno;
this.name = name;
this.std = std;
}
// getter and setter
public int getRollno() {
return rollno;
}
public String getName() {
return name;
}
public int getStd() {
return std;
}
}
public class Tut17 {
public static void main(String[] args) {
StudentRecord st = new StudentRecord(1, "Prathamesh");
System.out.println("Rollno : " + st.getRollno() + "\nName : " + st.getName() + "\nSTD : " + st.getStd());
StudentRecord st2 = new StudentRecord(2, "Sushant", 7);
System.out.println("Rollno : " + st2.getRollno() + "\nName : " + st2.getName() + "\nSTD : " + st2.getStd());
}
}