Why can't we instantiate a abstract class in J

2020-02-07 19:38发布

I understand:

  1. Since Abstract class are nothing on its own i.e. vehicle that's why we want to create an object of an concrete implementation like Car,Bike etc.
  2. Constructor of an Abstract class gets called during object chaining.

  3. We can never directly create an object of Abstract class even if it contains a Constructor and all methods are implemented

why ? I am looking to understand from Compiler perspective, why Java forces these ?

Thanks

15条回答
霸刀☆藐视天下
2楼-- · 2020-02-07 20:27

This is not a technical limitation, rather (as you have pointed out) a logical one. Java (and many other languages) enforce various rules not because they are impossible to break, but because this is an intentional part of the language.

查看更多
爷、活的狠高调
3楼-- · 2020-02-07 20:29

What I understand that Abstract classes may contain abstract (empty without implementation) methods. If we instantiate an object and call the empty method, It's not going to work and may cause problem, hence compiler forces this RULE. any further in-sighter ?

查看更多
走好不送
4楼-- · 2020-02-07 20:30

You can't instantiate abstract class because it's just to give a structure your class which is extending it.

And if you want to initiate your class, then why you want to define it as abstract?

查看更多
登录 后发表回答