Java在Dog1(){}这一行出现Implicit super constructorlucky dog1cg 图() is undefined. Must explicitly invoke

&&国之画&&&&&&
版权所有 京ICP备号-2
迷上了代码!myEclipse-- java程序提示信息英语翻译_百度知道博客访问: 52487
博文数量: 20
注册时间:
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
分类: Linux
先贴上部分源码:public class MyFindDialog extends Dialog implements ActionListener{ private Label lFind, lR private TextField tFind, tR private Button bFind, bR private TextA
public MyFindDialog() {
* 这里要调用一下父类的构造方法
* 原因个人觉得是:因为父类Dialog没有提供一个空的构造方法,
* 而编译器只可能帮我们自动调用那些空的构造方法(因为如果调用非空构造方法的话,编译器不知道为我们传什么参数)
* 所以我们只有在子类显示的调用这个方法。
super(new Frame());在没有super(new Frame());这行代码报错如下: implicit super constructor Dialog() is undefined, must explicitly invoke another constructor. 这是在写java程序,用到了继承时遇到的一个问题,虽然英文比较容易懂,但是当时感觉自己挺笨的,竟然对这个问题没有什么解决办法。回去之后,心里还是对那个问题念念不忘。仔细分析这句错误提示发现了解决方法。 这句错误提示的中文意思是:不明确的父类构造方法Dialog()(这里是Dialog因为我是从这个类继承的),没有定义,请明确调用另一个构造方法。 解决方法是:我查看了API,Dialog没有这个Dialog()构造方法,虽然我们知道如果一个类没有提供构造方法时,才会自动的为我们提供一个空的构造方法,但是因为Dialog()有其他的构造方法,所以那个默认的空的构造方法就不存在了(除非你自己显示的提供了一个空的构造方法)。好了这就到了问题的关键,既然Dialog没有空的构造方法,而编译器只会为我们自动的调用参数列表为空的构造方法,那么在我的代码里面必然会报错。此时,需要我们显示的调用一下父类的构造方法,然后问题得到解决。 然后说点这个Dialog类没有空构造方法原因,因为Dialog必须依托于一个组件而存在,我们的构造方法必然要指定这个Dialog的父亲是谁,空的构造方法怎么去指定这个父亲组件呢?然后你知道答案了....
阅读(5088) | 评论(0) | 转发(0) |
相关热门文章
给主人留下些什么吧!~~
请登录后评论。Java Inheritance error: Implicit Super Constructor is undefined - Stack Overflow
to customize your list.
Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
I am a novice to Java and just learning OOP concepts. Please review my code. I am getting the following error.- Implicit Super Constructor is undefined.
class BoxSuper
BoxSuper(BoxSuper obj)
height=obj.
length=obj.
width=obj.
BoxSuper(int a,int b,int c)
BoxSuper(int val)
height=length=width=
int volume()
return height*length*
class BoxSub extends BoxSuper
BoxSub(int a,int b,int c,int d)
17.6k43550
4,204154169
You are receiving this error because BoxSuper does not have a no-arg constructor.
During your constructor call in BoxSub, if you do not define the super constructor call Java tries to automatically call the no-arg super() constructor.
Either define a super constructor call in BoxSuper like so:
class BoxSub extends BoxSuper
BoxSub(int a,int b,int c,int d)
super(a, b, c);
or define a no-arg constructor in BoxSuper:
class BoxSuper
BoxSuper(){}
7,80022658
A constructor always calls the super constructor, always. If no explicit call to the super constructor is made, then the compiler tries to set it up so that it will call the default parameter-less constructor. If a default parameter-less constructor doesn't exist, a compilation error as you're seeing is shown and compilation will fail.
The solution in your case is to explicitly call the appropriate super constructor as the first line of your Box's constructor, and this makes perfect sense too if you think about it since you want to initialize the super with a, b, and c just as written in its constructor:
class BoxSub extends BoxSuper
BoxSub(int a,int b,int c,int d)
super(a, b, c);
// height=a;
// length=b;
// width=c;
229k15165254
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled

我要回帖

更多关于 lucky dog1cg 图 的文章

 

随机推荐