我们可以实例化一个抽象类吗?

故事扮演 提交于 2020-08-12 13:50:42

问题:

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!