-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructorTest.java
More file actions
73 lines (62 loc) · 1.66 KB
/
Copy pathConstructorTest.java
File metadata and controls
73 lines (62 loc) · 1.66 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
public class ConstructorTest {
public static void main(String[] args) {
GrandFather gf = new GrandFather();
gf.farming();
System.out.println("----------");
Father fa = new Father();
fa.banking();
fa.farming();
// fa.netting();
System.out.println("----------");
Child ch = new Child();
ch.banking();
ch.farming();
ch.netting();
System.out.println("---------------");
}
}
class GrandFather // extends Object
{
GrandFather() {
//super()
System.out.println("GrandFather() ctor.....");
}
void farming() {
System.out.println("GrandFather is farming...in an old way using the Bulls.");
}
}
class Father extends GrandFather
{
Father(int a) {
//super(); its a default line of every constructor, implicit/explicit
// and it is the very FIRST line inside a ctor
System.out.println("\tFather(int) ctor.....");
}
Father() {
//super(); its a default line of every constructor, implicit/explicit
// and it is the very FIRST line inside a ctor
System.out.println("\tFather() ctor.....");
}
void banking() {
System.out.println("Father is banking...by going into the Bank...");
}
void farming() { //OVERRIDING
System.out.println("Father is farming using a Tractor....");
}
}
class Child extends Father
{
Child() {
//super();
System.out.println("\t\tChild() ctor.....");
}
void netting() {
System.out.println("Child is netting....");
}
void farming() {
System.out.println("Child is farming...via Modern way...Automated Tractor...of John Deere....");
}
void banking() {
System.out.println("Child is banking...via internet.....");
}
}