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

Look at the following code: Line 1 public class ClassA Line 2 {Line 3 public Cla

ID: 3836129 • Letter: L

Question

Look at the following code: Line 1 public class ClassA Line 2 {Line 3 public ClassA () {} Line 4 public void method1 (int a) {} Line 5} Line 6 public class ClassB extends ClassA Line 7 {Line 8 public ClassB () {} Line 9 public void method1 () {} Line 10} Line 11 public class ClassC extends ClassB Line 12 {Line 13 public ClassC () {} Line 14 public void method1 () {} Line 15} Which method1 will be executed when the following statements are executed? Write down the line number or write down "This is an error and will cause the program to crash" if there is an error. ClassA item1 = new ClassB (); item1.method1 (); In a class hierarchy: a the more general classes are toward the bottom of the tree and the more specialized are toward the top. b the more general classes are toward the top of the tree and the more specialized are toward the bottom. c the more general classes are toward the left of the tree and the more specialized are toward the right. d the more general classes are toward the right of the tree and the more specialized are toward the left.

Explanation / Answer

Q19- This is an error as we are creating the object of class A and calling the method of class B which in turn is extending the class A so method1 of class A will be called and we are calling the method1 through the object without any argument but in our method defination we provided an integer type argument so this will create an error .

Q20- in general more general classes are towards the top of the tree and more specialized are towards the bottom of the tree. when message is sent to an object it is passed up in the inheritance tree starting from the class of the receiving object until a definition is found for the method and this process is called upcasting.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote