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 fieldlength
. It has two methods,calculateArea
that returns the area, andprintMyType
that outputs the type of the object. - Rectangle: This class also inherits from
Shape
and includes additional fieldslength
andbreadth
. It includes the same two methods asSquare
.
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 withlength = 5
, use theprintMyType
method, and then callcalculateArea
. - Create an instance of the
Rectangle
class withlength = 5
andbreadth = 4
, use theprintMyType
method, and then callcalculateArea
.
Constraints:
- Ensure methods and variables are correctly encapsulated within the appropriate classes.
length
andbreadth
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!
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


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
AmbitionBox Awards
Get AmbitionBox app

