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跟进(已经在 JRE System Library里面的rt.jar,右键→properties→Java Source Attachment,选择External File,定位到JDK根目录下的src.zip就可以了),总会跳到 Throwable.class中
public Throwable(String message, Throwable cause) {
处,再一直F7的话,依次跳到 ClassFoundException.class URLClassLoader.class(2次) ClassLoader.class Launcher.class ClassLoader.class 最后返回到new Student();语句处,再F5的话执行到下一条语句。其中在 Launcher.class 中出现如下信息:
Class File EditorSource not Found
The source attachment does not contain the source for the file Launcher.class.
You can change the source attachment by clicking Change Attached Source below:
// (version 1.5 : 49.0, super bit)
public class sun.misc.Launcher {
// Field descriptor #135 Ljava/net/URLStreamHandlerFactory;
private static java.net.URLStreamHandlerFactory factory;
// Field descriptor #136 Lsun/misc/Launcher;
private static sun.misc.Launcher launcher;
// Field descriptor #133 Ljava/lang/ClassLoader;
private java.lang.ClassLoader loader;
// Field descriptor #137 Lsun/misc/URLClassPath;
private static sun.misc.URLClassPath bootstrapClassPath;
// Field descriptor #134 Ljava/net/URLStreamHandler;
private static java.net.URLStreamHandler fileHandler;
// Method descriptor #150 ()Lsun/misc/Launcher;
// Stack: 1, Locals: 0
public static sun.misc.Launcher getLauncher();
0 getstatic sun.misc.Launcher.launcher : sun.misc.Launcher [204]
3 areturn
// Method descriptor #12 ()V
// Stack: 4, Locals: 5
public Launcher();
0 aload_0 [this]
1 invokespecial java.lang.Object() [213]
4 invokestatic sun.misc.Launcher$ExtClassLoader.getExtClassLoader() : sun.misc.Launcher$ExtClassLoader [243]
7 astore_1
8 goto 22
11 astore_2
12 new java.lang.InternalError [112]
15 dup
16 ldc <String "Could not create extension class loader"> [5]
18 invokespecial java.lang.InternalError(java.lang.String) [212]
21 athrow
问题:
1、如何找到 Launcher.class ,避免出现上面的信息
2、构造方法初始化是先调用父类的构造方法(如果在子类构造方法中没有用super()显示指定调用父类的哪个构造方法的话,默认是调用父类的无参构造方法方法;若用super()显示指定调用父类的哪个构造方法,则不调用父类的无参构造方法方法)。但是 在new Student("zhangshan",76,"武大");处设置断点,F5跳到 public Student(String name ,int age,String school)处,再F5跳到 public Person()处,再F5的话 跳到 Object.class中
public class Object {
处。显然与在 new Student();F5 的结果不一样。这又如何解释呢?
3、Object类没有构造方法,2、中跳到 public class Object { 后,程序又做了些什么动作,使得再次F5 又跳到 public Person()处了呢?
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跟进(已经在 JRE System Library里面的rt.jar,右键→properties→Java Source Attachment,选择External File,定位到JDK根目录下的src.zip就可以了),总会跳到 Throwable.class中
public Throwable(String message, Throwable cause) {
处,再一直F7的话,依次跳到 ClassFoundException.class URLClassLoader.class(2次) ClassLoader.class Launcher.class ClassLoader.class 最后返回到new Student();语句处,再F5的话执行到下一条语句。其中在 Launcher.class 中出现如下信息:
Class File EditorSource not Found
The source attachment does not contain the source for the file Launcher.class.
You can change the source attachment by clicking Change Attached Source below:
// (version 1.5 : 49.0, super bit)
public class sun.misc.Launcher {
// Field descriptor #135 Ljava/net/URLStreamHandlerFactory;
private static java.net.URLStreamHandlerFactory factory;
// Field descriptor #136 Lsun/misc/Launcher;
private static sun.misc.Launcher launcher;
// Field descriptor #133 Ljava/lang/ClassLoader;
private java.lang.ClassLoader loader;
// Field descriptor #137 Lsun/misc/URLClassPath;
private static sun.misc.URLClassPath bootstrapClassPath;
// Field descriptor #134 Ljava/net/URLStreamHandler;
private static java.net.URLStreamHandler fileHandler;
// Method descriptor #150 ()Lsun/misc/Launcher;
// Stack: 1, Locals: 0
public static sun.misc.Launcher getLauncher();
0 getstatic sun.misc.Launcher.launcher : sun.misc.Launcher [204]
3 areturn
// Method descriptor #12 ()V
// Stack: 4, Locals: 5
public Launcher();
0 aload_0 [this]
1 invokespecial java.lang.Object() [213]
4 invokestatic sun.misc.Launcher$ExtClassLoader.getExtClassLoader() : sun.misc.Launcher$ExtClassLoader [243]
7 astore_1
8 goto 22
11 astore_2
12 new java.lang.InternalError [112]
15 dup
16 ldc <String "Could not create extension class loader"> [5]
18 invokespecial java.lang.InternalError(java.lang.String) [212]
21 athrow
问题:
1、如何找到 Launcher.class ,避免出现上面的信息
2、构造方法初始化是先调用父类的构造方法(如果在子类构造方法中没有用super()显示指定调用父类的哪个构造方法的话,默认是调用父类的无参构造方法方法;若用super()显示指定调用父类的哪个构造方法,则不调用父类的无参构造方法方法)。但是 在new Student("zhangshan",76,"武大");处设置断点,F5跳到 public Student(String name ,int age,String school)处,再F5跳到 public Person()处,再F5的话 跳到 Object.class中
public class Object {
处。显然与在 new Student();F5 的结果不一样。这又如何解释呢?
3、Object类没有构造方法,2、中跳到 public class Object { 后,程序又做了些什么动作,使得再次F5 又跳到 public Person()处了呢?
st1:
person 无参数构造函数
student 无参数的构造函数
---------------------------
st2:
person 无参数构造函数
student 3 参数的构造函数
---------------------------
st3:
person 2 参数的构造函数
student 4 参数的构造函数,super().
public class Object { private static native void registerNatives();
static {
registerNatives();
}
public final native Class<?> getClass(); public native int hashCode();
public boolean equals(Object obj) {
return (this == obj);
}
protected native Object clone() throws CloneNotSupportedException;
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
public final native void notify();
public final native void notifyAll();
public final native void wait(long timeout) throws InterruptedException;
public final void wait(long timeout, int nanos) throws InterruptedException {
if (timeout < 0) {
throw new IllegalArgumentException("timeout value is negative");
} if (nanos < 0 || nanos > 999999) {
throw new IllegalArgumentException(
"nanosecond timeout value out of range");
} if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
timeout++;
} wait(timeout);
}
public final void wait() throws InterruptedException {
wait(0);
}
protected void finalize() throws Throwable { }
}
哪里有 Object()方法?