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

12. [10 Points] UML and Evaluate: The next set of questions use the following gr

ID: 3881514 • Letter: 1

Question

12. [10 Points] UML and Evaluate: The next set of questions use the following group of classes public class Snow public void method2) System.out.println("Snow 2" public void method3) system.out.println("Snow 3") public class Rain extends Snow t public void method1) System .ut . printin ("Rain 1"); public void method2) system.out.printin ("Rain 2") public void method2) system.out.println ("Sleet 2") super.method2 ) method3 0 public void method3() System.out.println("Sleet 3") public class Fog extends Sleet f public void methodl) f System.out.printin("Fog 1"); public void method3() ( System.out.println ("Fog 3") a. [4 Points] Draw a UML diagram representing the above code.

Explanation / Answer

Example 1:

out put is :

Sleet 2
Snow 2
Sleet 3

Explanation:

- Object of Sleet is created and you are calling the method2 from Sleet class, hence the first statement "Sleet2"

- inside Method2() of sleet class, you are calling Super.Method1() which means the method2() of Sleet's super class (i.e., Snow - because Sleet is extending the class Snow, hence Snow is the super class)

- third statement inside Method2() of sleet class is Method3() - which is directly pointing to the Method3() of Sleet class, since you are not using Super keyword, method will be called from the same class.

Example 2:

Reference variable is created using class Snow,

but there is no method availabe as method1(), Hence you will get a compile time error for this case.

Example 3:

A runtime exception will be thrown for this condition because, you are creating a reference variable of Snow, Typecasting it to Sleet and trying to create an object of class Rain.

Since there is no relationship between the class Sleet and Rain (Both are independent classes and hence you cannot do type case between those two classes), You will get a Runtime Exception.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote