eolymp
bolt
Try our new interface for solving problems
Problems

Java Inheritance Shape

published at 4/3/24, 11:05:18 pm

class Shape { private String shapeName;

Shape(String name) { this.shapeName = name; }

public String getShapeName() { return shapeName; }

public String toString() { return getShapeName(); }
}

class Circle extends Shape { // calling the constructor of the Shape class Circle() { super("Circle"); } }

class Rectangle extends Shape { // calling the constructor of the Shape class public Rectangle() { super("Rectangle"); } }

class Triangle extends Shape { // calling the constructor of the Shape class public Triangle() { super("Triangle"); } }