-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncapsulation.java
More file actions
45 lines (37 loc) · 1.05 KB
/
Encapsulation.java
File metadata and controls
45 lines (37 loc) · 1.05 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
39
40
41
42
43
44
45
public class Encapsulation{
static class human{
private String name;
private int age;
private String Grade;
public int getAge(){
return age;
}
public void setName(String name){
this.name=name;
}
public void setAge(int age){
this.age=age;
}
public void setGrade(String Grade){
this.Grade=Grade;
}
public int getName(){
return age;
}
public String getGrade() {
return Grade;
}
}
public static void main(String[] args) {
human obj1=new human();
obj1.setName("ravi");
obj1.setAge(20);
obj1.setGrade("A+");
System.out.println(obj1.getName()+" "+obj1.getAge()+""+" "+obj1.getGrade());
human obj2=new human();
obj2.setName("rolex");
obj2.setAge(21);
obj2.setGrade("B");
System.out.println(obj2.getName()+" "+obj2.getAge()+" "+obj2.getGrade());
}
}