-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOP_constructor_chaining.java
More file actions
38 lines (33 loc) · 1.4 KB
/
Copy pathOOP_constructor_chaining.java
File metadata and controls
38 lines (33 loc) · 1.4 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
class Demo
{
Demo()
{
this(80, 90); // Step 4: will call parameterized constructor of base class
System.out.println("Base class default constructor called"); // Step 6: will print this
}
Demo(int x, int y)
{
System.out.println("Base class parameterized constructor called"); // Step 5: print this
}
}
class Prototype extends Demo
{
Prototype()
{
this("Java", "Python"); // Step 2: will call parameterized constructor of derived class
System.out.println("Derived class default constructor called"); // Step 8 will print this
}
Prototype(String str1, String str2)
{
super(); // Step 3: will call default constructor of base class
// we can also call parameterized constructor of base class using super(int, int)
System.out.println("Derived class parameterized constructor called"); // Step 7: will print this
}
}
public class OOP_constructor_chaining
{
public static void main(String args[])
{
Prototype my_example = new Prototype(); // Step 1: will call default constructor of derived class
}
}