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

Please answer the following three questions Let class A be a superclass of B, an

ID: 3618726 • Letter: P

Question

Please answer the following three questions
  1. Let class A be a superclass of B, and B be asuperclass of C. Write the first line for the three classdefinitions. Define a variable x in another class (not A,B or C)such that x has static type A, and dynamic type C.
  2. Sometimes class/interface pairs exist in theJava standard library that define exactly the same methods. Theclass implements the interface, but all the methods have emptybodies, and no additional methods are defined. What might be thereason for having them both?
  3. Give pros and cons for multiple inheritance.Does Java have multiple inheritance?
Let class A be a superclass of B, and B be asuperclass of C. Write the first line for the three classdefinitions. Define a variable x in another class (not A,B or C)such that x has static type A, and dynamic type C. Sometimes class/interface pairs exist in theJava standard library that define exactly the same methods. Theclass implements the interface, but all the methods have emptybodies, and no additional methods are defined. What might be thereason for having them both? Give pros and cons for multiple inheritance.Does Java have multiple inheritance?

Explanation / Answer

Let class A be a superclass of B, and B be asuperclass of C. Write the first line for the three classdefinitions. Define a variable x in another class (not A,B or C)such that x has static type A, and dynamic typeC. public class A; public class B extendsA; public class C extendsB; public class Example { A x =new C(); } Sometimes class/interface pairs existin the Java standard library that define exactly the same methods.The class implements the interface, but all the methods have emptybodies, and no additional methods are defined. What might be thereason for having them both? This allows programmers to inherit from theclass, and implement only the methods they will be using. Otherwise, they would have to implement the interface, and leaveunused methods with empty bodies for every class using theinterface. Give pros and cons for multiple inheritance.Does Java have multiple inheritance? Pros: inheritance of behaviors from multiple sub-classes Cons: confusion as to which method to inherit when methods conflict. Java allows classes to implement multiple interfaces, meaning thatthey can be treated as different types by implementing theinterface's methods. However, Java does not allow multipleinheritance of classes.