-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTHIS.java
More file actions
35 lines (32 loc) · 921 Bytes
/
THIS.java
File metadata and controls
35 lines (32 loc) · 921 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
package BASICS;
class Animal{
private int age;
private String type;
String name;
// public void setData(int age,String type,String name,Animal A){
// Animal obj1=A;
// obj1.age=age;
// obj1.name=name;
// obj1.type=type;
// }
// to refer to the current object we can use 'this' keyword,
// now we don't need to take class object as params.
public void setData(int age,String type,String name){
this.age=age;
this.type=type;
this.name=name;
}
public void getData(){
System.out.println(age);
System.out.println(type);
System.out.println(name);
}
}
public class THIS {
public static void main(String[] args) {
Animal obj = new Animal(); //obj is reference object.
new Animal(); //this is an Anonymous Object
obj.setData(4,"Mammal","Cat");
obj.getData();
}
}