-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeirarchical.java
More file actions
66 lines (63 loc) · 869 Bytes
/
Heirarchical.java
File metadata and controls
66 lines (63 loc) · 869 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//super class
class Base
{
int a;
Base()
{
System.out.println("Base class ctor ");
a=10;
}
}
//sub class
class Child1 extends Base
{
int x;
Child1()
{
System.out.println("Child1 class ctor ");
x=100;
}
void show()
{
System.out.println(a+" "+x);
}
}
//sub class
class Child2 extends Base
{
int b;
Child2()
{
System.out.println("Child2 class ctor ");
b=200;
}
void show()
{
System.out.println(a+" "+b);
}
}
//sub class
class Child3 extends Base
{
int c;
Child3()
{
System.out.println("Child3 class ctor ");
c=300;
}
void show()
{
System.out.println(a+" "+c);
}
}
class Heirarchical
{
public static void main(String[] args) {
Child1 ch=new Child1();
ch.show();
Child2 ch1=new Child2();
ch1.show();
Child3 ch2=new Child3();
ch2.show();
}
}