-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_16_This_keyword.java
More file actions
56 lines (52 loc) · 1.5 KB
/
Copy path_16_This_keyword.java
File metadata and controls
56 lines (52 loc) · 1.5 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
// refers to the current object inside a methord or constructor.
//public class _16_This_keyword {
// void show(){
// System.out.println(this);
// }
// public static void main(String[] args) {
// _16_This_keyword r = new _16_This_keyword();
// System.out.println(r);
// r.show();
// }
//}
// defines the instance variable as this. and when local and instance variable are same.
//public class _16_This_keyword {
// int a;
// _16_This_keyword(int a){
// this.a=a;
// }
// void show(){
// System.out.println(a);
// }
// public static void main(String[] args) {
// _16_This_keyword r = new _16_This_keyword(100);
// r.show();
// }
//}
//it is also used when we want to call the default constructor of own class.
//public class _16_This_keyword {
// _16_This_keyword(){
// System.out.println("hello");
// }
// _16_This_keyword(int a){
// this(); // calls default constructor.
// System.out.println(a);
// }
// void show(){
// }
// public static void main(String[] args) {
// _16_This_keyword r = new _16_This_keyword(100);
// }
//}
// it also calls parametrized constructor of its own class.
public class _16_This_keyword {
_16_This_keyword(){
this(10);
}
_16_This_keyword(int a){
System.out.println(a);
}
public static void main(String[] args) {
_16_This_keyword r = new _16_This_keyword();
}
}