-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThis.java
More file actions
39 lines (33 loc) · 704 Bytes
/
This.java
File metadata and controls
39 lines (33 loc) · 704 Bytes
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
/*
TODO: Understand the concept of this keyword.
*/
public class This
{
int a;
void fun()
{
System.out.println("fun called by 'this' keyword");
n(this);
}
public This()
{
System.out.println("We can call different constructor by this keyword");
}
public This(int a)
{
this();
this.a = a;
System.out.println("This can be used to intialize the instance variables if they have same name");
this.fun();
}
void n(This obj)
{
System.out.println("this can also passed as an arguement (Used in event handling)");
System.out.println("And can also be passed to constructor");
}
public static void main(String args[])
{
This obj = new This(1);
obj.fun();
}
}