Untitled

mail@pastecode.io avatar
unknown
java
7 months ago
676 B
4
Indexable
Never
abstract class Shape {
	public void numberOfSides(){};
}

class Rectangle extends Shape {
	public void numberOfSides() {
		System.out.println("Number of sides of Rectangle = 4");
	}
}

class Triangle extends Shape {
	public void numberOfSides() {
		System.out.println("Number of sides of Triangle = 3");
	}
}

class Hexagon extends Shape {
	public void numberOfSides() {
		System.out.println("Number of sides of Hexagon = 6");
	}
}

public class AbstractClass {
	public static void main(String[] args) {
		Rectangle rec = new Rectangle();
		Triangle tri = new Triangle();
		Hexagon hex = new Hexagon();
		rec.numberOfSides();
		tri.numberOfSides();
		hex.numberOfSides();
	}
}
Leave a Comment