Q - Given:-
interface I {
public void displayI ( );
}
abstract class C2 implements I {
public void displayC2 ( ) {
System.out.print ("C2");
}
}
class C1 extends C2 {
public void displayI ( ) {
System.out.print ("C1");
}
}
And the code fragment:-
C2 obj1= new C1( );
I obj2 = new C1 ( );
C2 s= (C2) obj2 ;
I t = obj1;
t.displayI( );
s.displayC2( );
What is the result?
A) C2C2
B) C1C1
C) Compilation fails.
D) C1C2
⧪ please give your answer in a comment section.
interface I {
public void displayI ( );
}
abstract class C2 implements I {
public void displayC2 ( ) {
System.out.print ("C2");
}
}
class C1 extends C2 {
public void displayI ( ) {
System.out.print ("C1");
}
}
And the code fragment:-
C2 obj1= new C1( );
I obj2 = new C1 ( );
C2 s= (C2) obj2 ;
I t = obj1;
t.displayI( );
s.displayC2( );
What is the result?
A) C2C2
B) C1C1
C) Compilation fails.
D) C1C2
⧪ please give your answer in a comment section.
6 Comments
C
ReplyDeleteC
ReplyDeleteC) Compilation fails.
ReplyDeletet.displayI( ): should be written as t.displayI( );
C
ReplyDeleteC
ReplyDeleteD is the correct answer 100%
ReplyDelete