-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncapsulation.java
More file actions
45 lines (41 loc) · 1.01 KB
/
Copy pathEncapsulation.java
File metadata and controls
45 lines (41 loc) · 1.01 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
package oopsConcepts;
public class Encapsulation {
private String Name;
private int Roll;
private int Age;
public int getAge()
{
return Age;
}
public String getName()
{
return Name;
}
public int getRoll()
{
return Roll;
}
public void setAge( int newAge)
{
Age = newAge;
}
public void setName(String newName)
{
Name = newName;
}
public void setRoll( int newRoll)
{
Roll = newRoll;
}
//Here we can only access in this class as it is PRIVATE type..If declared in other class it fails
public static void main (String[] args)
{
Encapsulation obj = new Encapsulation();
obj.setName("Harsh");
obj.setAge(19);
obj.setRoll(51);
System.out.println("My name: " + obj.getName());
System.out.println("My age: " + obj.getAge());
System.out.println("My roll: " + obj.getRoll());
}
}