Inheritance and Polymorphism Exam- Questions &
Answers 100% Correct| Newest Update 2025
11.7 Which of the following is incorrect?
A. A constructor may be static.
B. A constructor may be private.
C. A constructor may invoke a static method.
D. A constructor may invoke an overloaded constructor.
E. A constructor invokes its superclass no-arg constructor by default if a constructor
does not invoke an overloaded constructor or its superclass?s constructor. - ✔✔A. A
constructor may be static.
11.8 Which of the statements regarding the super keyword is incorrect?
A. You can use super to invoke a super class constructor.
B. You can use super to invoke a super class method.
C. You can use super.super.p to invoke a method in superclass's parent class.
D. You cannot invoke a method in superclass's parent class. - ✔✔C. You can use
super.super.p to invoke a method in superclass's parent class.
11.9 Analyze the following code:
public class Test {
public static void main(String[] args) {
B b = new B();
b.m(5);
System.out.println("i is " + b.i);
}
,}
class A {
int i;
public void m(int i) {
this.i = i;
}
}
class B extends A {
public void m(String s) {
}
}
A. The program has a compile error, because m is overridden with a different signature
in B.
B. The program has a compile error, because b.m(5) cannot be invoked since the
method m(int) is hidden in B.
C. The program has a runtime error on b.i, because i is not accessible from b.
D. The method m is not overridden in B. B inherits the method m from A and defines an
overloaded method m in B. - ✔✔D. The method m is not overridden in B. B inherits
the method m from A and defines an overloaded method m in B.
11.10 The getValue() method is overridden in two ways. Which one is correct?
I:
public class Test {
, public static void main(String[] args) {
A a = new A();
System.out.println(a.getValue());
}
}
class B {
public String getValue() {
return "Any object";
}
}
class A extends B {
public Object getValue() {
return "A string";
}
}
II:
public class Test {
public static void main(String[] args) {
A a = new A();
System.out.println(a.getValue());
}
}
Answers 100% Correct| Newest Update 2025
11.7 Which of the following is incorrect?
A. A constructor may be static.
B. A constructor may be private.
C. A constructor may invoke a static method.
D. A constructor may invoke an overloaded constructor.
E. A constructor invokes its superclass no-arg constructor by default if a constructor
does not invoke an overloaded constructor or its superclass?s constructor. - ✔✔A. A
constructor may be static.
11.8 Which of the statements regarding the super keyword is incorrect?
A. You can use super to invoke a super class constructor.
B. You can use super to invoke a super class method.
C. You can use super.super.p to invoke a method in superclass's parent class.
D. You cannot invoke a method in superclass's parent class. - ✔✔C. You can use
super.super.p to invoke a method in superclass's parent class.
11.9 Analyze the following code:
public class Test {
public static void main(String[] args) {
B b = new B();
b.m(5);
System.out.println("i is " + b.i);
}
,}
class A {
int i;
public void m(int i) {
this.i = i;
}
}
class B extends A {
public void m(String s) {
}
}
A. The program has a compile error, because m is overridden with a different signature
in B.
B. The program has a compile error, because b.m(5) cannot be invoked since the
method m(int) is hidden in B.
C. The program has a runtime error on b.i, because i is not accessible from b.
D. The method m is not overridden in B. B inherits the method m from A and defines an
overloaded method m in B. - ✔✔D. The method m is not overridden in B. B inherits
the method m from A and defines an overloaded method m in B.
11.10 The getValue() method is overridden in two ways. Which one is correct?
I:
public class Test {
, public static void main(String[] args) {
A a = new A();
System.out.println(a.getValue());
}
}
class B {
public String getValue() {
return "Any object";
}
}
class A extends B {
public Object getValue() {
return "A string";
}
}
II:
public class Test {
public static void main(String[] args) {
A a = new A();
System.out.println(a.getValue());
}
}