-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccessModifierDemo.java
More file actions
30 lines (30 loc) · 878 Bytes
/
Copy pathAccessModifierDemo.java
File metadata and controls
30 lines (30 loc) · 878 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
class Person {
public String name = "Deepika";
private int age = 21;
protected String city = "chennai";
String country = "India";
public void displayPublic() {
System.out.println("Public Method: Name = "+ name);
}
private void displayPrivate(){
System.out.println("Private Method: Age = "+ age);
}
protected void displayProtected(){
System.out.println("Protected Method: City = "+ city);
}
void displayDefault() {
System.out.println("Default Method: Country = "+ country);
}
public void showPrivate() {
displayPrivate();
}
}
public class AccessModifierDemo {
public static void main(String[] args){
Person p = new Person();
p.displayPublic();
p.showPrivate();
p.displayProtected();
p.displayDefault();
}
}