HOTSPOT
You have the following class definitions.
There might be other classes derived from Shape.
You are creating an application that evaluates whether an object is a square, a rectangle, or another shape.
You need to implement a switch statement that meets the following requirements:
• If the shape variable is of the Rectangle type, and the width and the height are NOT equal, the output must be Rectangle.
• If the shape variable is of the Rectangle type, and the width and the height are equal, the output must be Square.
• If the shape variable is of any other Shape derived type, the output must be Unknown.
• If the shape variable does NOT refer to an object, the output must be Empty.
How should you complete the code? To answer, select the appropriate options in the answer area.
NOTE: Each correct selection is worth one point.
Answer: Explanation:
The first answer is “when”
Leave a Reply