Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class Mysquare – In the constructor, print out the following message “I’

ID: 3769779 • Letter: W

Question

Write a class Mysquare – In the constructor, print out the following message “I’m a quadrilateral, I have four right angles and I have four equal sides.” Write three classes Quadrilateral and Rectangle inherited from Quadrilateral and Square inherited from Rectangle The constructors (without parameter) of the above three classes will print out the following messages Quadrilateral – I’m a quadrilateral Rectangle – I have four right angles Square – I have four equal sides Write a demo class to create objects of above four classes

Explanation / Answer

package current;

public class MySquare {

   public MySquare () {
       System.out.println("I’m a quadrilateral, I have four right angles and I have four equal sides");
   }
  
   public static void main(String[] theArgs) {
       System.out.println("--------------------MySquare Constructor------------------------");
       MySquare msq = new MySquare();
       System.out.println("--------------------Quadrilateral Constructor------------------------");
       Quadrilateral quad = new Quadrilateral();
       System.out.println("--------------------Rectangle Constructor------------------------");
       Rectangle rect = new Rectangle();
       System.out.println("--------------------Square Constructor------------------------");
       Square square = new Square();
      
   }
}

class Square extends Rectangle {
   public Square () {
       System.out.println(" I have four equal sides");
   }
}

class Rectangle extends Quadrilateral {
   public Rectangle() {
       System.out.println("I have four right angles");
   }
}

class Quadrilateral {
   public Quadrilateral() {
       System.out.println("I’m a quadrilateral");
   }
}

--------------------output----------------------------------

--------------------MySquare Constructor------------------------
I’m a quadrilateral, I have four right angles and I have four equal sides
--------------------Quadrilateral Constructor------------------------
I’m a quadrilateral
--------------------Rectangle Constructor------------------------
I’m a quadrilateral
I have four right angles
--------------------Square Constructor------------------------
I’m a quadrilateral
I have four right angles
I have four equal sides

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote