-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstraction.java
More file actions
105 lines (80 loc) · 2.23 KB
/
Abstraction.java
File metadata and controls
105 lines (80 loc) · 2.23 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.java;
abstract class animal {
abstract void sound();
}
class lion extends animal{
void sound() {
System.out.println("lion rore");
}
}
class tiger extends animal{
void sound(){
System.out.println("tiger rore");
}
}
abstract class shape{
abstract double calculateArea();
abstract double calculatePerimeter();
}
class circle extends shape {
private int radius = 5;
double calculateArea() {
return Math.PI * radius * radius;
}
double calculatePerimeter() {
return 2 * Math.PI * radius;
}
}
class Triangle extends shape{
private int side1 = 1;
private int side2 = 2;
private int side3 = 3;
private int len = 5;
private int brth = 6;
double calculateArea() {
return 0.5*len*brth;
}
double calculatePerimeter(){
return side1+side2+side3;
}
}
abstract class Bank{
abstract void deposit();
abstract void withdraw();
}
class SavingsAccount extends Bank{
void deposit(){
System.out.println("Deposit in savings bank");
}
void withdraw(){
System.out.println("Withdraw from savings bank");
}
}
class CurrentAccount extends Bank{
void deposit(){
System.out.println("Deposit in Current account");
}
void withdraw(){
System.out.println("Withdraw from current account");
}
}
public class Abstraction {
public static void main(String[] arg){
animal obj = new lion();
obj.sound();
obj=new tiger();
obj.sound();
shape s = new circle();
System.out.println("Area of circle :" + s.calculateArea());
System.out.println("Perimeter of circle :" + s.calculatePerimeter());
s = new Triangle();
System.out.println("Area of triangle is :"+ s.calculateArea());
System.out.println("perimeter of triangle is :"+s.calculatePerimeter());
Bank b = new SavingsAccount();
b.deposit();
b.withdraw();
b = new CurrentAccount();
b.withdraw();
b.deposit();
}
}