-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11. Abstract class.java
More file actions
60 lines (58 loc) · 1.18 KB
/
11. Abstract class.java
File metadata and controls
60 lines (58 loc) · 1.18 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
//This is an class Qs
// Shape class Qs
import java.util.*;
abstract class Shape
{
abstract void numberOfSides();
}
class Trapezoid extends Shape
{
public void numberOfSides()
{
System.out.println("Number of sides is: 4");
}
}
class Triangle extends Shape
{
public void numberOfSides()
{
System.out.println("Number of sides is: 3");
}
}
class Rectangle extends Shape
{
public void numberOfSides()
{
System.out.println("Number of sides is: 4");
}
}
class Hexagon extends Shape
{
public void numberOfSides()
{
System.out.println("Number of sides is: 6");
}
}
class MyJClass11
{
public static void main(String arg[])
{
int c;
System.out.println("Menu\n1. Trapezium\n2. Triangle\n3. Rectangle\n4. Hexagon\n");
System.out.println("Enter the Shape of Choice:");
Scanner s = new Scanner(System.in);
c = s.nextInt();
switch(c)
{
case 1: Trapezoid t = new Trapezoid();
t.numberOfSides();break;
case 2: Triangle q = new Triangle();
q.numberOfSides();break;
case 3: Rectangle r = new Rectangle();
r.numberOfSides();break;
case 4: Hexagon h = new Hexagon();
h.numberOfSides();break;
default: System.out.println("Invalid Choice");
}
}
}