为什么不能创建抽象类的对象? [英] Why can't an object of abstract class be created?

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

问题描述

在我看来,这是一个场景,我已经在Google上搜索了很多,但还是得到了类似的答案

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

抽象类尚未实现方法,因此我们无法创建对象" 单词'Abstract'指示编译器不要创建该类的对象"

"Abstract class has not implemented method so, we cant create the object" "The word 'Abstract' instruct the compiler to not create an object of the class"

但是在一个简单的类中,我们拥有所有虚方法,能够创建一个对象?

But in a simple class where we have all virtual method, able to create an object???

此外,我们可以定义对Abstract类构造函数进行修改的不同访问权限,例如private,protected或public.

Also, we can define different access modified to Abstract class constructor like private, protected or public.

我的搜索终止于以下问题:

My search terminated to this question:

为什么我们不能创建Abstract类的对象?

Why we can't create object of an Abstract class?

推荐答案

抽象类型已被定义,因为它是无法创建的.您可以为其创建 subtypes ,但不能创建该类型本身. CLI不允许您这样做.

An abstract type is defined largely as one that can't be created. You can create subtypes of it, but not of that type itself. The CLI will not let you do this.

abstract类具有protected构造函数(默认情况下),允许派生类型对其进行初始化.

An abstract class has a protected constructor (by default) allowing derived types to initialize it.

例如,基本类型Stream是抽象的.如果没有派生类型,数据将流向何处?调用abstract方法时 happen 会是什么?该调用方法将没有实际的实现.

For example, the base-type Stream is abstract. Without a derived type where would the data go? What would happen when you call an abstract method? There would be no actual implementation of the method to invoke.

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

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