Shape and Method Overriding Problem Statement

Create a base class called Shape that contains a field named shapeType and a method printMyType.

Implement two derived classes:

  • Square: This class inherits from Shape and includes an additional field length. It has two methods, calculateArea that returns the area, and printMyType that outputs the type of the object.
  • Rectangle: This class also inherits from Shape and includes additional fields length and breadth. It includes the same two methods as Square.

Example:

Input:
// No specific input - This is an object-oriented programming task
Output:
Create a Square object with a length of 5:
Square
Area: 25

Create a Rectangle object with a length of 5 and breadth of 4:
Rectangle
Area: 20

Explanation:

In the main method, you should follow these steps:

  • Create an instance of the Square class with length = 5, use the printMyType method, and then call calculateArea.
  • Create an instance of the Rectangle class with length = 5 and breadth = 4, use the printMyType method, and then call calculateArea.

Constraints:

  • Ensure methods and variables are correctly encapsulated within the appropriate classes.
  • length and breadth are non-negative integers.

Note:

Focus on proper class design and method overriding principles. This problem emphasizes object-oriented programming concepts.

AnswerBot
4mo

Create base class Shape with field shapeType and method printMyType. Implement Square and Rectangle classes with calculateArea method.

  • Create a base class Shape with shapeType field and printMyType met...read more

Help your peers!
Select
Add answer anonymously...

Hexaware Technologies Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Can you write an essay on any topic and present it verbally?
A Software Developer Intern was asked Q. Shape and Method Overriding Problem Statement Create a base class called Shape t...read more
A Software Developer Intern was asked Q. Fishmonger Toll Optimization Problem A fishmonger needs to transport goods from ...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Can you write an essay on any topic and present it verbally?
A Software Developer Intern was asked Q2. Shape and Method Overriding Problem Statement Create a base class called Shape t...read more
A Software Developer Intern was asked Q3. Fishmonger Toll Optimization Problem A fishmonger needs to transport goods from ...read more
Hexaware Technologies Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits