forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncapsulation.java
More file actions
50 lines (38 loc) · 882 Bytes
/
Encapsulation.java
File metadata and controls
50 lines (38 loc) · 882 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
42
43
44
45
46
47
48
49
50
package oops;
import java.util.Scanner;
public class Encapsulation {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
Encap e = new Encap();
System.out.println("Values of Variables");
System.out.println("A = ");
e.a = s.nextInt();
System.out.println("C = ");
e.c = s.nextInt();
System.out.println("D = ");
e.d = s.nextInt();
e.get();
e.disp();
s.close();
}
}
class Encap extends AccessSpecifier {
int a;
private int b;
protected int c;
public int d;
Scanner s = new Scanner(System.in);
public void get() {
System.out.println("Enter the value of B = ");
b = s.nextInt();
}
protected void disp() {
System.out.println("Addition of all variables = " + (a + b + c + d));
System.out.println("i : " + i);
System.out.println("j : " + j);
}
}