-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructorOverload.java
More file actions
86 lines (69 loc) · 1.61 KB
/
ConstructorOverload.java
File metadata and controls
86 lines (69 loc) · 1.61 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class Student
{
static int rollno=100;
private
final static String university;
private String Homecity;
Student()
{
Student.rollno ++;
}
Student(int rollno, String name)
{
rollno++;
this.name = name;
}
Student(int rollno, String name,String branch)
{
this.rollno = rollno;
this.name = name;
this.branch = branch;
}
Student(int rollno, String name,String branch, String City)
{
this.rollno = rollno;
this.name = name;
this.branch = branch;
this.city = City;
}
void display()
{
System.out.println("Student " + rollno + " " + name + "");
}
int getRollno()
{
return this.rollno;
}
String getName()
{
return this.name;
}
void setRollno(int rollno)
{
this.rollno = rollno;
}
void setName(String name)
{
this.name = name;
}
}
public class ConstructorOverload {
public static void main(String[] args)
{
Student s1= new Student();
Student s2= new Student(18,"krishna");
Student s3= new Student(19,"gopi","CSE");
Student s4= new Student(20,"vamsi","ECE","KADAPA");
s1.display();
s2.display();
s3.display();
s4.display();
System.out.println("After updating ");
s1.setRollno(21);
s1.setName("Nandhu");
s1.display();
System.out.println("to get roll number AND STUDENTNAME OF S3 ");
System.out.println(s3.getRollno());
System.out.println(s3.getName());
}
}