为什么我们不能在JAVA中实例化一个抽象类? [英] Why can't we instantiate a abstract class in JAVA?

查看:126
本文介绍了为什么我们不能在JAVA中实例化一个抽象类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我明白:


  1. 由于抽象类本身不存在,即汽车,这就是为什么我们要创建一个具体实现的对象像汽车,自行车等。

  2. 抽象类的构造函数在对象链接期间被调用。


  3. 从不直接创建抽象类的对象,即使它包含一个构造函数并且实现了所有方法。


为什么?
我希望从编译器的角度理解,为什么Java强制这些?



感谢

这不是一个技术限制,而是(如你所指出的)一个逻辑。 Java(和许多其他语言)执行各种规则,不是因为它们不可能破解,而是因为这是语言的有意的部分。


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

解决方案

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.

这篇关于为什么我们不能在JAVA中实例化一个抽象类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆