Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Shape {
- public void printShape() {
- System.out.println("This is shape");
- }
- }
- class Rectangle extends Shape {
- @Override
- public void printShape() {
- System.out.println("This is rectangular shape");
- }
- }
- class Circle extends Shape {
- @Override
- public void printShape() {
- System.out.println("This is circular shape");
- }
- }
- class Square extends Rectangle {
- public void printSquare() {
- System.out.println("Square is a rectangle");
- }
- }
- public class Main {
- public static void main(String[] args) {
- Square squareObj = new Square();
- // Call the method of the Shape class through the Square object
- squareObj.printShape(); // This will print "This is rectangular shape"
- // Call the method of the Rectangle class through the Square object
- squareObj.printSquare(); // This will print "Square is a rectangle"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement