【问题标题】:Method syntax java [duplicate]方法语法java [重复]
【发布时间】:2018-07-04 10:27:24
【问题描述】:

当你认为你已经看到了这一切时,下面的代码会在我希望学习的 java .class 中弹出。

我不完全确定这里发生了什么。首先声明了clean();,但它看起来既像一个字段又像一个方法?

然后它下面的另一种方法使用这个clean();,尽管在声明后backets中没有任何代码?

我很困惑。谁能解释一下这个语法?

public abstract void clean();

/**
 * Clean method called whenever the user interface is closed, in order to clean
 * internal and user-defined structures properly.
 */
void cleanFromUI()
{
    // clean user-specific items
    try
    {
        clean();
    }
    catch (EzException eze)
    {
        // do not display anything as the interface is being closed
        if (!eze.catchException) throw eze;
    }

    // clear all variables

    ezVars.clear();

    ezgui = null;

    synchronized (nbInstances)
    {
        nbInstances.setValue(nbInstances.getValue() - 1);
    }
}

【问题讨论】:

标签: java methods syntax format


【解决方案1】:

在您的代码中,我观察到了 1 个抽象方法。因此类将是抽象的。 抽象类永远不能被实例化。如果您想使用它的成员,您必须扩展此类并为该抽象方法提供实现。然后您可以调用该方法,该方法又调用 clean() 方法。

注:抽象类提供部分实现,并为子类提供实现并完成它设定标准。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-16
    • 2015-10-08
    • 2016-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-20
    • 2021-09-17
    相关资源
    最近更新 更多