-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathThisExample.java
More file actions
38 lines (36 loc) · 1.03 KB
/
ThisExample.java
File metadata and controls
38 lines (36 loc) · 1.03 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
class Newton {
String name ;
int mobile ;
int userId ;
void printMobile () {
System.out.println(this.mobile);
}
void printBoth () {
printMobile(); // java by default aise case this
System.out.println(this.name);
}
Newton() {
System.out.println("I am empty constructor");
}
Newton(String name , int mobile) {
this();
this.name = name;
this.mobile = mobile;
System.out.println("I am 2 paramter constructor");
}
Newton(String name , int mobile , int userId) {
this(name , mobile);
this.userId = userId;
System.out.println("I am 3 paramter constructor");
}
}
public class ThisExample {
public static void main(String[] args) {
Newton new1 = new Newton("vishal" , 991581);
Newton new12= new Newton("vishal" , 991581 , 12345);
System.out.println(new1.name);
System.out.println(new12.mobile);
System.out.println(new12.name);
System.out.println(new12.mobile);
}
}