Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:关于继承的问题?请大家帮忙!! [Re:hamlet]
blueoxygen





发贴: 31
积分: 2
于 2006-01-06 16:41 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
楼主没有借助好一点的IDE来写代码么?
虽然开始的时候编译打包等工作自己手动最好,但是用IDE能够帮助你更早发现问题。
你这段代码在IDEA里面根本就是提示错误的,你就更不会去编译然后产生疑问了。
而且从提示你就大概能猜出来怎么回事。下面是改进后的代码。
当你用原始代码的时候,IDE提示A没有默认构造函数。
因为如果类的定义中提供了带参数的构造器,则编译器不会再帮助你构造默认的无参构造器。此时如果你想调用new 一个class用无参的构造器就会出错。那么同理,此刻你的A提供了有参构造器,则A便不会在编译期间产生默认无参构造器,然后B继承了他,并且没有提供构造函数,编译器会试图产生一个无参构造器给他,但是第一步要默认调用父类无参构造器,可是A没有,这就是错误所在。
这些从IDE早期的错误提示中就可以自己揣摩出来。
感谢斑竹的耐心讲解,还是深入java虚拟机这本书好。

/**
* Created by IntelliJ IDEA.
* User: david
* Date: 2006-1-6
* Time: 16:39:29
* To change this template use File | Settings | File Templates.
*/
public class A
{
int i;

A(int k)
{
this.i = k;
}

}
class B extends A
{
B(int k){
super(k);

}
public static void main(String args[])
{

A a12 = new A(10);

System.out.println(a12.i);

}
}


why edited on 2006-01-09 20:53

i'll be a happy designer

话题树型展开
人气 标题 作者 字数 发贴时间
17188 关于继承的问题?请大家帮忙!! hamlet 310 2005-09-25 10:27
15021 Re:关于继承的问题?请大家帮忙!! wyql 279 2005-09-26 17:23
14942 Re:关于继承的问题?请大家帮忙!! freelow 66 2005-09-26 16:40
14719 Re:关于继承的问题?请大家帮忙!! panther 0 2005-09-26 18:57
14781 Re:关于继承的问题?请大家帮忙!! ranchgirl 493 2005-09-27 12:22
15309 Re:关于继承的问题?请大家帮忙!! ranchgirl 881 2005-09-27 11:49
15571 Re:关于继承的问题?请大家帮忙!! ranchgirl 2786 2005-09-27 12:09
14908 Re:关于继承的问题?请大家帮忙!! ranchgirl 235 2005-09-27 12:16
16094 Re:关于继承的问题?请大家帮忙!! Jcat 507 2005-09-27 18:06
14850 Re:关于继承的问题?请大家帮忙!! ranchgirl 312 2005-09-28 11:02
15273 Re:关于继承的问题?请大家帮忙!! bukaoyan 67 2005-09-29 11:37
14727 Re:关于继承的问题?请大家帮忙!! chinamicrofox 260 2006-01-05 03:00
14730 Re:关于继承的问题?请大家帮忙!! blueoxygen 823 2006-01-06 16:41
15071 Re:关于继承的问题?请大家帮忙!! hamlet 7 2005-09-26 13:00
15140 Re:关于继承的问题?请大家帮忙!! hamlet 41 2005-09-25 10:31
15003 Re:关于继承的问题?请大家帮忙!! ranchgirl 215 2005-09-25 10:40
15153 Re:关于继承的问题?请大家帮忙!! hamlet 66 2005-09-25 11:01
14955 Re:关于继承的问题?请大家帮忙!! ranchgirl 1602 2005-09-25 16:56
15054 Re:关于继承的问题?请大家帮忙!! ruoruowudi 229 2005-09-25 13:25
15188 Re:关于继承的问题?请大家帮忙!! freelow 345 2005-09-25 16:23
15618 Re:关于继承的问题?请大家帮忙!! ranchgirl 191 2005-09-25 16:38
15007 Re:关于继承的问题?请大家帮忙!! freelow 42 2005-09-26 11:36
14874 Re:关于继承的问题?请大家帮忙!! ranchgirl 15 2005-09-26 12:32

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923