The letter D is correct, a ClassCastException occurs, because B2 is an object of type C and class C has no inheritance from class B, so it cannot overload.
class A {
public void test() {
System.out.println("A");
}
}
class B extends A{
public void test() {
System.out.println("B");
}
}
public class C extends B {
public void test() {
System.out.println("C");
}
public static void main(String[] args) throws InterruptedException {
A b1= new A();
A b2 = new C();
A b3 = (B) b2;
b1 = (A) b2;
b1.test();
b3.test();
}
}
Answer: C
class A {
public void test() {
System.out.println("A");
}
}
class B extends A{
public void test() {
System.out.println("B");
}
}
public class C extends B {
public void test() {
System.out.println("C");
}
public static void main(String[] args) throws InterruptedException {
A b1= new A();
A b2 = new C();
A b3 = (B) b2;
b1 = (A) b2;
b1.test();
b3.test();
}
}
//output:
C
C
This section is not available anymore. Please use the main Exam Page.1z0-808 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
iSnover
Highly Voted 2 years, 6 months agodin_sub077
Most Recent 4 weeks, 1 day agoMPignaProTech
5 months, 3 weeks agosina_
1 year, 8 months agojackymak
1 year, 9 months agojackymak
1 year, 8 months agoMontassarTrablelsi
1 year, 8 months ago