fred rosenberger wrote:you can use the javap command to read the class file:
C:\slop>javap Dog.class
Compiled from "Dog.java"
public class Dog extends Animal {
Dog();
}
C:\slop>javap Animal.class
Compiled from "Dog.java"
class Animal {
Animal();
}
C:\slop>
Thanks Fred.
I was able to run 'javap' and got the following:
G:\>javap Animal.class
Compiled from "ConstructorExample_02.java"
class com.learning.java.Animal {
java.lang.String name;
java.lang.String nameOfOwner;
com.learning.java.Animal();
com.learning.java.Animal(java.lang.String);
}
G:\>javap Dog.class
Compiled from "ConstructorExample_02.java"
class com.learning.java.Dog extends com.learning.java.Animal {
java.lang.String name;
int age;
int weight;
com.learning.java.Dog();
com.learning.java.Dog(java.lang.String);
com.learning.java.Dog(java.lang.String, int);
com.learning.java.Dog(java.lang.String, int, int);
public java.lang.String getName();
}
I did not see any code related to Animal inside Dog.class file. It simply states that Dog extends Animal (2nd line in Dog.class).
So, exactly how the things happen at runtime can you please elaborate a little? Till now, I was assuming that all the permitted (non private) code related to superclass is copied into subclass bytecode, since subclass inherits those properties and methods. But, this is not the exact scene as I was assuming.
Can I assume that at runtime,
Java runtime links the Animal class with Dog class somehow? And if it is true, then how?