-
Notifications
You must be signed in to change notification settings - Fork 0
/
abstractClass.java
51 lines (39 loc) · 1.93 KB
/
abstractClass.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
****************************************************************************************************************************************************************************************************************
* File : abstractClass.java
* Description : 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.
* Author : Jibin Gigi
* Version : 1.0
* Date : 27/10/23
* *************************************************************************************************************************************************************************************************************/
public class abstractClass {
public static void main(String [] args) {
Rectangle rectangle=new Rectangle();
rectangle.numberOfSides();
Triangle triangle=new Triangle();
triangle.numberOfSides();
Hexagon hexagon=new Hexagon();
hexagon.numberOfSides();
}
}
abstract class Shapes{
int sides;
abstract void numberOfSides() ;
}
class Rectangle extends Shapes{
void numberOfSides(){
System.out.println("No. of sides of Rectangle:4");
}
}
class Triangle extends Shapes {
void numberOfSides(){
System.out.println("Enter the no. of sides of Triangle:3 ");
}
}
class Hexagon extends Shapes{
void numberOfSides(){
System.out.println("Enter the no. of sides of Hexagon: 6");
}
}