-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSides.java
More file actions
42 lines (41 loc) · 1.35 KB
/
Sides.java
File metadata and controls
42 lines (41 loc) · 1.35 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
# Write a java program to create an abstract class named Shape that contains an empty method named numberOfSides( ).
# Provide three classes named Rectangle, Triangle and Hexagon such that each one of the classes extends the class Shape.
# Each one of the classes contains only the method numberOfSides( ) that shows the number of sides in the given geometrical structures.
abstract class Shape
{
abstract void numberofsides();
}
class Rectangle extends Shape
{
void numberofsides()
{
System.out.println("Number of sides of Rectangle is : 4");
}
}
class Triangle extends Shape
{
void numberofsides()
{
System.out.println("Number of sides of Triangle is : 3");
}
}
class Hexagon extends Shape
{
void numberofsides()
{
System.out.println("Number of sides of Hexagon is : 6");
}
}
class Sides
{
public static void main(String args[])
{
Shape s;
s=new Rectangle();
s.numberofsides();
s=new Triangle();
s.numberofsides();
s=new Hexagon();
s.numberofsides();
}
}