问题:
During one of my interview, I was asked "If we can instantiate an abstract class?" 在我的一次采访中,有人问我“我们是否可以实例化一个抽象类?”
My reply was "No. we can't". 我的回答是“不,我们不能。” But, interviewer told me "Wrong, we can." 但是,面试官告诉我“错了,我们可以。”
I argued a bit on this. 我对此有些争论。 Then he told me to try this myself at home. 然后他告诉我自己在家尝试一下。
abstract class my {
public void mymethod() {
System.out.print("Abstract");
}
}
class poly {
public static void main(String a[]) {
my m = new my() {};
m.mymethod();
}
}
Here, I'm creating instance of my class and calling method of abstract class. 在这里,我正在创建类的实例和抽象类的调用方法。 Can anyone please explain this to me? 有人可以向我解释一下吗? Was I really wrong during my interview? 面试中我真的错了吗?
解决方案:
参考一: https://stackoom.com/question/vMRr/我们可以实例化一个抽象类吗参考二: https://oldbug.net/q/vMRr/Can-we-instantiate-an-abstract-class
来源:oschina
链接:https://my.oschina.net/u/4438370/blog/4281739