Why can't an object of abstract class be created?

前端 未结 16 967
误落风尘
误落风尘 2020-12-02 21:25

Here is a scenario in my mind and I have googled, Binged it a lot but got the answer like

\"Abstract class has not implemented method so, we cant create the object\

16条回答
  •  误落风尘
    2020-12-02 21:37

    Sorry guys...

    You can Create object for an abstract class, if and only if that abstract class does not contains any abstract method.

    Here is my Example. Copy it and compile and run.

    abstract class Example {
      void display(){
        System.out.println("Hi I am Abstract Class.");
      }
    }
    
    class ExampleDemo {
        public static void main(String[] args) {
            Example ob = new Example(){};
            ob.display();
       }
    }
    

    So your answer is yes, we can create object for abstract class if it's no Abstract Method. Check my program.

提交回复
热议问题