为什么super()没有显示错误,虽然没有在第一行给出? [英] Why does the super() not showing error though not given in first line?

查看:189
本文介绍了为什么super()没有显示错误,虽然没有在第一行给出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么超级关键字没有显示错误,虽然没有在第一行给出

Why does the super keyword not showing error though not given in first line

推荐答案

它对我有用:

class Superclass
{
}

class Subclass extends Superclass
{
    Subclass()
    {
        System.out.println();
        super();
    }
}

编译时出错:

Test.java:10: call to super must be first statement in constructor
        super();
             ^
1 error

请用它显示类似的简短但完整的程序给出错误。请注意,我假设你真的有 super(); 而不是说, super.foo(); 这只是对 foo(); 的超类实现的调用,可以出现在方法或构造函数的任何地方。

Please show a similar short but complete program with it not giving an error. Note that I'm assuming you really have got super(); rather than, say, super.foo(); which is just a call to the superclass implementation of foo(); and can appear anywhere in a method or constructor.

这篇关于为什么super()没有显示错误,虽然没有在第一行给出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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