How should you complete the code?

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.
Hot Area:

microsoft-exams

4 thoughts on “How should you complete the code?

    1. for Rectangle it should be:

      case Rectangle r when (!r.Width.Equals(r.Height))

      Note: case Rectangle r when (r.Width ! = r.Height)) will not work because there is space between ! & = sign

      1. Nop, thats just how it looks.

        (!r.Width.Equals(r.Height)) does not end with double colon, so it won’t work.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.