为什么在new Student();处F5无法跟进

ewwerpm 2010-05-14 02:45:35
eclipse下编译一下代码
class Person
{
public Person()
{
System.out.println("person 无参数构造函数");
}
public Person(String name,int age)
{
System.out.println("person 2 参数的构造函数");
}
}
class Student extends Person
{
public Student()
{
System.out.println("student 无参数的构造函数");
}
public Student(String name ,int age,String school)
{
System.out.println("student 3 参数的构造函数");
}
public Student(String name ,int age,String school,String grade)
{
super(name,age);
System.out.println("student 4 参数的构造函数,super().");
}
}
class MyHelloApply
{
public static void main(String [] args)
{
System.out.println("st1:");
new Student();
System.out.println("---------------------------");
System.out.println("st2:");
new Student("zhangshan",76,"武大");
System.out.println("---------------------------");
System.out.println("st3:");
new Student("lisi",24,"武大","研究生");
}
}

——1、在 new Student();处无论按F5还是F6都跟不进去啊.为什么呢?
2、在new Student("zhangshan",76,"武大");处设置断点,F5跳到 public Student(String name ,int age,String school)处,再F5跳到 public Person()处,再F5的话就“Source not found.”为什么呢?
...全文
80 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zfq642773391 2010-05-14
  • 打赏
  • 举报
回复
我也遇到过这种问题,说不出是哪的问题 可能是debug的bug吧 呵呵
ewwerpm 2010-05-14
  • 打赏
  • 举报
回复
代码完全可以run,我只是想debug一下啊,看看是如何运行的
[Quote=引用 8 楼 zfq642773391 的回复:]
就是debug不行,代码补全
[/Quote]
zfq642773391 2010-05-14
  • 打赏
  • 举报
回复
就是debug不行,代码补全
WayneMarkRooney 2010-05-14
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 ewwerpm 的回复:]

1、F6没问题,单步跳过就行了。关键是在new Student();处想按F5跟进去,按理说应该跳到public Student()行,但跳不过去,你能跳过去吗?
2、如何关联java源码啊?我已经装了jad,但只能手动跳。是要设置还是要下什么包啊?
引用 3 楼 waynemarkrooney 的回复:
1、我复制了你的代码到我的环境里,追踪断点,F5和F6都没问题,试着重启MyEcli……
[/Quote]

1、我的F5是跳到那一行的,没什么问题;
2、在你的工程中找到JRE System Library里面的rt.jar,右键→properties→Java Source Attachment,选择External File,定位到JDK根目录下的src.zip就可以了。
ewwerpm 2010-05-14
  • 打赏
  • 举报
回复
我是说debug,请看清楚问题
[Quote=引用 2 楼 lacus87 的回复:]
楼主的代码我复制运行了下,输出没有问题啊:

st1:
person 无参数构造函数
student 无参数的构造函数
---------------------------
st2:
person 无参数构造函数
student 3 参数的构造函数
---------------------------
st3:
person 2 参数的构造函数
student 4 参数……
[/Quote]
ewwerpm 2010-05-14
  • 打赏
  • 举报
回复
我已经装了jad,但只能手动跳。意思是ctrl+点击就能看到相关类的源码,但F5看不到啊
ewwerpm 2010-05-14
  • 打赏
  • 举报
回复
1、F6没问题,单步跳过就行了。关键是在new Student();处想按F5跟进去,按理说应该跳到public Student()行,但跳不过去,你能跳过去吗?
2、如何关联java源码啊?我已经装了jad,但只能手动跳。是要设置还是要下什么包啊?
[Quote=引用 3 楼 waynemarkrooney 的回复:]
1、我复制了你的代码到我的环境里,追踪断点,F5和F6都没问题,试着重启MyEclipse试试看;
2、这个问题一楼正解,关联一下Java源码,你会看得更清楚。
[/Quote]
WayneMarkRooney 2010-05-14
  • 打赏
  • 举报
回复
1、我复制了你的代码到我的环境里,追踪断点,F5和F6都没问题,试着重启MyEclipse试试看;
2、这个问题一楼正解,关联一下Java源码,你会看得更清楚。
lacus87 2010-05-14
  • 打赏
  • 举报
回复
楼主的代码我复制运行了下,输出没有问题啊:

st1:
person 无参数构造函数
student 无参数的构造函数
---------------------------
st2:
person 无参数构造函数
student 3 参数的构造函数
---------------------------
st3:
person 2 参数的构造函数
student 4 参数的构造函数,super().
lodachi 2010-05-14
  • 打赏
  • 举报
回复
第二个好理解 程序执行顺序就是那样的 执行子类的构造方法之前会调用父类的构造方法 Person没有父类 就会找Object类的构造方法 因为你没有Object类的源码所以提示Source not found

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧