-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingleinheritence.java
More file actions
64 lines (64 loc) · 1.74 KB
/
Copy pathsingleinheritence.java
File metadata and controls
64 lines (64 loc) · 1.74 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
class InheritanceStudent{
String name;
}
class Info extends InheritanceStudent{
int rollno;
public void getinfo(){
System.out.println("Name:"+this.name);
System.out.println("RollNo:"+this.rollno);
}
}
class Age extends Info{
int age;
@Override
public void getinfo(){
System.out.println("Name:"+this.name);
System.out.println("RollNo:"+this.rollno);
System.out.println("Age:"+this.age);
}
}
class Student1 extends Age{
int marks;
public void proinfo(){
System.out.println("Name:"+this.name);
System.out.println("RollNo:"+this.rollno);
System.out.println("Age:"+this.age);
System.out.println("Marks:"+this.marks);
}
}
class Student2 extends Age{
String clas;
public void printinfo(){
System.out.println("Name:"+this.name);
System.out.println("RollNo:"+this.rollno);
System.out.println("Age:"+this.age);
System.out.println("Class:"+this.clas);
}
}
public class singleinheritence{
public static void main(String[] args) {
Info in1=new Info();
in1.name="Abdullah";
in1.rollno=306;
in1.getinfo();
System.out.println("Mutliple Inheritence");
Age ag1=new Age();
ag1.name="Usman";
ag1.rollno=337;
ag1.age=20;
ag1.getinfo();
System.out.println("Hairrechcal Inheritence");
Student1 s1=new Student1();
Student2 s2=new Student2();
s1.name="Abdullah";
s1.rollno=306;
s1.age=18;
s1.marks=333;
s1.proinfo();
s2.name="Usman";
s2.age=22;
s2.rollno=337;
s2.clas="se";
s2.printinfo();
}
}