-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncapsulation1.java
45 lines (38 loc) · 1 KB
/
Encapsulation1.java
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
class Student{
private int age ;
private String name ;
Student(int age , String name)
{
this.age = age ;
this.name = name ;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void show(){
System.out.println(name + " " + age);
}
}
public class Encapsulation1 {
public static void main(String[] args) {
Student obj = new Student(5,"Rahul");
Student obj1 = new Student(8 ,"Pradeep");
int stud1Age = obj.getAge();
System.out.println(stud1Age);
String stud1Name = obj.getName();
System.out.println(stud1Name);
int stud2Age = obj1.getAge();
System.out.println(stud2Age);
String stud2Name = obj1.getName();
System.out.println(stud2Name);
}
}