Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
46 lines (35 loc) · 921 Bytes

File metadata and controls

46 lines (35 loc) · 921 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package Constructor;
public class ConstEx1 {
// if we won't provide any constructor compiler adds default constructor
// int this case, ConstEx1(){} , but if we provide any other constructor
// compiler won't add.
int x, y;
// no-argument constructor
ConstEx1() {
getX(); // we can call both static and non-static method from
// constructor
x = 0;
y = 0;
}
// Parameterized Constructor
ConstEx1(int l) {
x = y = l;
getX();
}
ConstEx1(int l, int m) {
x = l;
y = m;
}
static void getX() {
System.out.println(" You're inside method getX() ");
// return x;
}
public static void main(String[] args) {
ConstEx1 c1 = new ConstEx1();
System.out.println("[C1]X= " + c1.x + " Y= " + c1.y);
ConstEx1 c2 = new ConstEx1(20);
ConstEx1 c3 = new ConstEx1(12, 13);
System.out.println("[C2]X= " + c2.x + " Y= " + c2.y);
System.out.println("[C3]X= " + c3.x + " Y= " + c3.y);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.