-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththis.java
More file actions
46 lines (34 loc) · 676 Bytes
/
this.java
File metadata and controls
46 lines (34 loc) · 676 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
40
41
42
43
44
45
/*1. This keyword refers to the current object of the class or instance variable.
Example
int a; // this refer to instance variable because, instance variable is part of the object of class A.
class A{
int a;
A(int a)
{
this.a=a;
}
}
2. This keyword is also used to call the default constructor of the same class .
3. 2. Example
class A{
A()
{
System.out.println("Hello I am default constructor");
}
A(int a)
{
this(); // this will call the default constructor
}
}
3.It also call the parameterized constructor as same as 2nd.
class A{
A(int a)
{
System.out.println("Hello I am default constructor");
}
A()
{
this(100); // call parameterized constructor
}
}
*/