必须从java中的抽象类实现什么? [英] what must be implemented from an abstract class in java?

查看:85
本文介绍了必须从java中的抽象类实现什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的有两个问题。我试图了解继承是如何工作的。

I have two questions really. I'm trying to get a handle on how inheritance works.

如果我有一个要从中继承的抽象类,并且它有一个未标记为抽象的方法,那么这个方法仍然需要在子类中实现?

If I have an abstract class to inherit from, and it has a method that is not labelled abstract does this method still need to be implemented in the subclass?

如果我有一个继承自另一个子类的子类,然后从一个抽象类继承,那么最低的子类需要在抽象类中实现方法吗?或者因为这些方法已在中间子类中实现,它们不需要再次实现?

If I have a subclass that is inheriting from another subclass, which is then inheriting from an abstract class, does the lowest subclass need to implement the methods in the abstract class? Or because the methods have been implemented in the middle subclass, they don't need to be implemented again?

谢谢!

推荐答案

抽象类是一个声明为abstract的类。它可能包括也可能不包括抽象方法。抽象类不能被实例化,但它们可以被子类化。

An abstract class is a class that is declared abstract. It may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.

抽象方法是一种声明没有实现的方法(没有大括号,后跟分号),像这样:

An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon), like this:

abstract void moveTo(double deltaX, double deltaY);

如果类包含抽象方法,则类本身必须声明为abstract,如:

If a class includes abstract methods, the class itself must be declared abstract, as in:

public abstract class GraphicObject {
    // declare fields
    // declare non-abstract methods
    abstract void draw();
}

当抽象类被子类化时,子类通常提供所有的实现父类中的抽象方法。但是,如果没有,则子类也必须声明为abstract

When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, the subclass must also be declared abstract

这篇关于必须从java中的抽象类实现什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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