Answer is A.
To test:
Use the shortcut (Ctrl + Shift + f) in eclipse to fix the indentation in case the text appears badly formatted.
interface I {
public void displayI();
}
abstract class C2 implements I {
public void displayC2() {
System.out.println("C2");
}
}
class C1 extends C2 {
public void displayI() {
System.out.print("C1");
}
}
public class Test {
public static void main(String[] args) {
C2 obj1 = new C1();
I obj2 = new C1();
C2 s = (C2) obj2;
I t = obj1;
t.displayI();
s.displayC2();
}
}
The correct answer is the letter A, the cast can be done because "C1" can be "C2" as it inherits the methods of "C2" by inheritance. Printing C1C2.
upvoted 1 times
...
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.
MPignaProTech
2 months, 2 weeks agocarloswork
2 years, 2 months agoiSnover
2 years, 3 months ago