-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram 6 (constructor chaining)
49 lines (46 loc) · 1.07 KB
/
program 6 (constructor chaining)
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
Question : -Write a Java program to
illustrate Constructor
Chaining.
Code:
class constructor {
constructor(){
this("SHAILESH");
System.out.println("\ndefault constructor called\n");
}
constructor(String name){
this("Sarvadnya",19);
System.out.println("second constructor called\n");
}
constructor(String name,int age){
System.out.println("third constructor called\n");
}
public static void main(String[] args) {
System.out.println("Sarvadnya_Awaghad_D10A_05");
new constructor();
}}
public class base
{
base()
{ this(5);
System.out.println("Parent Default Constructor is called!!\n"); }
base(int x) {
System.out.println("Parent Parameterized Constructor is called!!\n");
}
}
public class derived extends base
{
derived() {
this(7);
System.out.println("Derived Default Constructor is called!!\n");}
derived(int y) {
super();
System.out.println("Derived Parameterized Constructor is called!!\n");
}
}
public class Main
{
// instance variables - replace the example below with your own
public static void main(String args[]) {
System.out.println("Sarvadnya_Awaghad_D10A_05");
new derived();}
}