Problems
Java Inheritance Shape
Java Inheritance Shape
Implement a class Shape.
Implement classes Circle, Rectangle, Triangle that extend Shape.
class Shape
{
private String shapeName; // private variable
Shape(String name) // Constructor
public String getShapeName() // return name of the shape
public String toString() // Print the variable
}
class Circle extends Shape
{
Circle() // Constructor
}
class Rectangle extends Shape
{
Rectangle() // Constructor
}
class Triangle extends Shape
{
Triangle() // Constructor
}
Input
Each line contains one of the next words:
- Circle
- Rectangle
- Triangle
Output
For each word create a corresponding class and print the name of the shape.
Input example #1
Circle Rectangle Triangle Rectangle
Output example #1
Circle Rectangle Triangle Rectangle