-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThis_Keyword.java
More file actions
41 lines (28 loc) · 881 Bytes
/
Copy pathThis_Keyword.java
File metadata and controls
41 lines (28 loc) · 881 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
class Human{
private String name;
private int age;
//These instance variables are made private so that it is not accessible from outside the class directly
void setName(String name){
this.name = name;
}
void setAge(int age){
this.age = age;
//Here the "age" variable that is being passed as an argument on the right side is a local variable
//And the "age" variable on the left hand side is the "instance variable"
}
String getName(){
return name;
}
int getAge(){
return age;
}
}
class This_keyword{
public static void main(String[] args){
Human h=new Human();
h.setAge(24);
h.setName("Aditya Singh");
System.out.println("The name of the person - "+ h.getName());
System.out.println("The age of the person - "+ h.getAge());
}
}