Welcome Guest | Sign in | Register
Interface - Discussion Page For Q.2869 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Interface > Questions and Answers

Q: interface A{
Int i=0;
}
interface B extends A{
Int i=1;
}
interface C extends B{
Int i=2;
}
Class Manager implements A
{
Int i=3;
Public static void main(String args[])
{
C c1=(C)new Manager();
System.out.println(c1.i);
}
}
A. 3 B. ClassCastException
C. compile time error D. none of the above

Answer and Explanation

Answer:ClassCastException

Explanation:
Here a class Manager implements A which is an interface so it will not throw any compile time error, but while creating an object we are creating an object of manager and trying to store in an c1 variable which is of type C.actually manager is of type A not of type C.. So it will throw ClassCastException.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.