-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay6_Constructors.java
More file actions
154 lines (132 loc) · 3.31 KB
/
Day6_Constructors.java
File metadata and controls
154 lines (132 loc) · 3.31 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// topics
// 1.Diff bw constructors and instance blocks
// 2.Rules for writing constructors
// 3.default Constructor
// 4.super(),this() methods
// 5.super , this keywords
// 6.Overloaded Constructors
// ------------------------------------------------------------------------
// class Test
// {
// {
// System.out.println("instance called");
// }
// Test()
// {
// System.out.println("constructor called");
// }
// }
// public class Day6_Constructors
// {
// public static void main(String[] pavan)
// {
// Test t = new Test();
// }
// }
// -----------------------
// class Test
// {
// String name;
// {
// System.out.println("instance called........................");
// }
// Test()
// {
// System.out.println("constructor called............................");
// }
// Test(String n)
// {
// name = n;
// System.out.println("constructor called............................"+name);
// }
// }
// public class Day6_Constructors
// {
// public static void main(String[] pavan)
// {
// Test t = new Test();
// Test t2 = new Test("anna pavan");
// }
// }
// ----------------------------------------------------------------
// class Test
// {
// Test()
// {
// System.out.println("constructor called............................");
// }
// }
// public class Day6_Constructors
// {
// private Day6_Constructors()
// {
// System.out.println("constructor called............................private");
// }
// public static void main(String[] pavan)
// {
// Day6_Constructors d = new Day6_Constructors();
// }
// }
// -------------------------------------------------------------------------------------------
// super() , this()
// class Test
// {
// int i;
// Test()
// {
// System.out.println("constructor called..........Test..........");
// }
// Test(int n)
// {
// System.out.println("constructor called..........Test..........int");
// }
// }
// public class Day6_Constructors extends Test
// {
// String name;
// int j;
// Day6_Constructors()
// {
// System.out.println("constructor called..........Day6.............");
// }
// Day6_Constructors(int m)
// {
// System.out.println("constructor called..........Day6.............int");
// }
// Day6_Constructors(String n)
// {
// super(40);
// // this(10);
// System.out.println("constructor called..........String");
// // super(40); //call to super must be first statement in constructor
// }
// public static void main(String[] pavan)
// {
// // Day6_Constructors d = new Day6_Constructors();
// Day6_Constructors d = new Day6_Constructors("pavan");
// }
// }
// super vs this keyword
class Test
{
int x=100;
public static void m2()
{
System.out.println("m2");
}
}
class Day6_Constructors extends Test1
{
int x=1000;
public static void main(String arhs[])
{
Day6_Constructors d = new Day6_Constructors();
d.m1();
}
public void m1()
{
System.out.println(this.x);
System.out.println(super.x);
super.super.m2();
}
}