-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOPS.java
More file actions
51 lines (43 loc) · 966 Bytes
/
OOPS.java
File metadata and controls
51 lines (43 loc) · 966 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
51
// Encapsulation
public class OOPS {
public static void main(String[] args) {
Pen p1 = new Pen();
p1.setColor("Blue");
System.err.println(p1.getColor());
p1.setTip(5);
System.out.println(p1.getTip());
p1.setColor("Yellow");
System.out.println(p1.getColor());
}
}
class BankAccount{
public String username;
private String password;
public void setPassword(String pwd){
password = pwd;
}
}
class Pen{
private String color;
private int tip;
String getColor() {
return this.color;
}
int getTip() {
return this.tip;
}
void setColor(String newColor){
this.color = newColor;
}
void setTip(int tip){
this.tip = tip;
}
}
class Student {
String name;
int age;
float percentage; // CGPA
void calcPercentage(int phy,int chem, int math) {
percentage = (phy + chem + math)/3;
}
}