Letter D is correct. C2 and I are not parent/child class to each other. Implicit casting will not work.
At least, we will need to explicitly cast
C2 s = (C2) obj2;
I t = (I) obj1;
even runtime objects are assignable to the references, but at compile time compiler refuse to compile, because there is not any IS-A relation between I and C2
Answer is D:
class C2 {
public void displayC2(){
System.out.println("C2");
}
}
interface I {
public void displayI();
}
class C1 extends C2 implements I {
public void displayI() {
System.out.println("C1");
}
}
public class Test {
public static void main(String[] args) {
C2 obj1 = new C1();
I obj2 = new C1();
C2 s = obj2;
I t = obj1;
t.displayI();
s.displayC2();
}
}
D. C2 and I are not parent/child class to each other. Implicit casting will not work.
At least, we will need to explicitly cast
C2 s = (C2) obj2;
I t = (I) obj1;
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.
pawankalyan
Highly Voted 3 years, 6 months agoakbiyik
Most Recent 1 week, 4 days agoiSnover
2 months agoJongHwa
1 year agoCapWin
1 year, 6 months agoSesha_2
1 year, 9 months agoTarik2190
1 year, 10 months agoBabirye
2 years, 2 months agoHarid
2 years, 3 months agov323rs
2 years, 11 months agoletmein2
3 years, 3 months agorasifer
3 years, 5 months ago