A superclass has the following method: public void setValue(int v) {value = v;}
ID: 3836125 • Letter: A
Question
A superclass has the following method: public void setValue(int v) {value = v;} Write a statement that may appear in a subclass that calls this method, passing 10 as an argument. 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 method 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. Class C item1 = new ClassA (); item1.method1 ();Explanation / Answer
17. Inorder to call the method in the super class,
super.setValue(10);
18. When you try to compile the program, you will get the error at the below line itself
-->ClassC item1 = new ClassA();
error: incompatible types: ClassA cannot be converted to ClassC
"This is an error and will cause the program to crash"
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.