面试题选择,求解释,,,,谢了
7、Given the folowing classes which of the following will compile without
error?
interface IFace{}
class CFace implements IFace{}
class Base{}
public class ObRef extends Base{
public static void main(String argv[]){
ObRef ob = new ObRef();
Base b = new Base();
Object o1 = new Object();
IFace o2 = new CFace();
}
}
A. o1=o2; B. b=ob; C. ob=b; D. o1=b;
------解决方案--------------------
刚刚看的不仔细,正确应该是 A B D ,A是因为所有类都默认继承自Object类,所以也在同一个继承树上,D也在同一个继承树上,是将子类实例赋值给父类的父类,刚刚没看好,呵呵