简体   繁体   English

在java中,一个类可以同时具有抽象性和具体性吗?

[英]Can a class be abstract and concrete at the same time in java?

Have a doubt : 有疑问:

Can a class be abstract and concrete at the same time in java? 在java中,一个类可以同时具有抽象性和具体性吗? ie if an abstract class has no abstract methods in it, then can it be called a concrete class. 即如果抽象类中没有抽象方法,那么它可以被称为具体类。 Also can we say that any and every class that has no abstract method be called a concrete class? 我们还可以说任何没有抽象方法的类都被称为具体类吗?

The main difference lies in the documentation where it states: 主要区别在于它所声明的文档

An abstract class is a class that is declared abstract—it may or may not include abstract methods. 抽象类是一个声明为abstract的类 - 它可能包含也可能不包含抽象方法。 Abstract classes cannot be instantiated, but they can be subclassed. 抽象类无法实例化,但可以进行子类化。

Instantiation is the key here. 实例化是关键。

The answers are "no" and "no". 答案是“不”和“不”。 Abstract classes are only those that have been declared with the keyword abstract , whether or not they contain abstract methods. 抽象类只是那些用关键字abstract声明的类,无论它们是否包含抽象方法。 A non-abstract class is not allowed to contain abstract methods. 非抽象类不允许包含抽象方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM