-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path11_Basic problems on classes and object
86 lines (69 loc) · 1.73 KB
/
11_Basic problems on classes and object
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class Employee1{
int salary;
String name;
public int getSalary(){
return salary;
}
public String getName(){
return name;
}
public void setName(String n){
name = n;
}
}
class CellPhone{
public void ringing(){
System.out.println("Ringing...");
}
public void vibrating() {
System.out.println("Vibrating...");
}
public void callFriend() {
System.out.println("Calling...");
}
}
class Square{
int side;
public int area(){
return side * side;
}
public int perimeter(){
return 4 * side;
}
}
class Rectangle{
int breadth;
int height;
public int area(){
return breadth * height;
}
public int perimeter(){
return 2*(breadth + height);
}
}
public class practiceset4 {
public static void main(String[] args) {
// Problem 1
Employee1 gg = new Employee1();
gg.setName("GG");
gg.salary = 77;
System.out.println("My salary is : "+gg.getSalary());
System.out.println("and my name is : "+gg.getName());
// Problem 2
CellPhone apple = new CellPhone();
apple.ringing();
apple.vibrating();
apple.callFriend();
// Problem 3
Square sq = new Square();
sq.side=5;
System.out.println("Area of square is : "+sq.area());
System.out.println("Perimeter of the square is : "+sq.perimeter());
// Problem 4
Rectangle rc = new Rectangle();
rc.breadth= 5;
rc.height=6;
System.out.println("Area of the rectangle is : "+rc.area());
System.out.println("Perimeter of the rectangle is : "+rc.perimeter());
}
}