-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstract1.java
56 lines (52 loc) · 1.54 KB
/
abstract1.java
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
import java.util.Scanner;
abstract class Shape{
public Shape()
{
System.out.println("Constructor of Class Shape");
}
abstract protected void volume();
abstract public void totalSurfaceArea();
}
class Cube extends Shape {
private double side;
Cube(double s){
side=s;
}
public void volume(){
System.out.println("Volume is "+(side*side*side));
}
public void totalSurfaceArea(){
System.out.println("Total Surface area is "+(6*side*side));
}
}
class Cuboid extends Shape {
private double length,breadth,height,sa;
Cuboid(double l,double b,double h){
length = l; breadth = b; height = h;
}
public void volume(){
System.out.println("Volume is "+(length*breadth*height));
}
public void totalSurfaceArea() {
sa=2*((length*breadth)+(breadth*height)+(length*height));
System.out.println("Total Surface Area is "+sa);
}
}
public class abstract1 {
public static void main(String[] args) {
double l,b,h,s;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the side of the Cube");
s = sc.nextDouble();
Shape s1 = new Cube(s);
s1.volume();
s1.totalSurfaceArea();
System.out.println("Enter the Length,Breadth and Height of the Cuboid");
l=sc.nextDouble();
b=sc.nextDouble();
h=sc.nextDouble();
Shape s2 = new Cuboid(l,b,h);
s2.volume();
s2.totalSurfaceArea();
}
}