与抽象类一起使用new [英] using new with abstract class

查看:56
本文介绍了与抽象类一起使用new的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.
是否可以使用new运算符在另一个类中定义类似以下内容的抽象类:

Hello .
is it possible to use new operator to define abstract class in another class something like this :

abstract class x
{} 
class y {
x j=new x();


如果不能,请告诉我y?


if not can tell me y ?

推荐答案

不能实例化抽象类,这就是new不起作用的原因.
An abstract class cannot be instantiated, and that''s why new doesn''t work.


否.抽象类无法实例化,这意味着它们不能出现在new 运算符的右侧.
但是,您可以使用extends 关键字从x 派生y ,它将以这种方式获取内容.
No. Abstract classes cannot be instantiated, which means they cannot appear on the right hand side of a new operator.
You can however derive y from x by using the extends keyword and it will get the content that way.


不,这是不可能的. [
No, it''s not possible. This[^] is why.


这篇关于与抽象类一起使用new的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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