Skip to content

Commit 2631841

Browse files
committed
COnstructor ,static ,this and final demo
1 parent 9f9ea77 commit 2631841

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

OOPs1.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//Constructors
2+
class Student{
3+
int rn;
4+
String name;
5+
String subject;
6+
static final String instituteName = "APSMind";
7+
Student(){
8+
System.out.println("I am default constructor.");
9+
}
10+
Student(int rn,String name){
11+
System.out.println("I am parametrized(2) constructor.");
12+
this.rn = rn;
13+
this.name = name;
14+
}
15+
Student(int rn,String name,String subject){
16+
this(rn,name);
17+
System.out.println("I am parametrized(3) constructor.");
18+
this.subject = subject;
19+
}
20+
public void showStudent(){
21+
System.out.println(rn);
22+
System.out.println(name);
23+
System.out.println(subject);
24+
System.out.println(instituteName);
25+
}
26+
}
27+
28+
class Simple{
29+
public static void main(String[] args){
30+
Student s = new Student(1,"Ramu Kaka");
31+
//s.instituteName = "ABCDEFG";
32+
s.showStudent();
33+
34+
Student s2 = new Student(2,"ABCX","Java");
35+
s2.showStudent();
36+
}
37+
}

0 commit comments

Comments
 (0)