Does invoking a constructor mean creating object?

前端 未结 8 1507
情书的邮戳
情书的邮戳 2020-12-06 05:26

When we create a Subclass object which extends an abstract class, the abstract class constructor also runs . But we know we cannot create objects of an abstract class. Hence

8条回答
  •  北海茫月
    2020-12-06 05:49

    I am completely disagree that the object for an abstract class can not be created and only jvm can does it in case of Inheritance even a programmer can do it a t times whenever or wherever he/she intends to do so by using the concept of anonymous class: Look at this code and try it by your Own

    abstract class Amit{ 
    void hai()
    {System.out.print("Just Wanna say Hai");}
    abstract void hello();
    }
    class Main{
    stic public void main(String[]amit)
    {
    Amit aa=new Amit(){
    void hello(){Sstem.out.print("I actually dont say hello to everyone");
    }};
    aa.hello(); }}
    

提交回复
热议问题