Re: Inheritance and lousy Frame
Ian Wilson wrote:
<snip>
When you run a Java application, it runs the main() method of the
specified class. If your main method does nothing then nothing is what
happens.
Maybe between the two lines I've quoted you should instantiate an object
by inserting
DogClass rex = new DogClass();
I think "Dog" is a better classname than "DogClass". You know it is a
class because it starts with a capital letter. This is why "Tail" is a
poor name for a variable (use "tail" instead).
Thank you all. It is working now with your help. Ok, lessions learned
for me:
a) subclass object must be instantiated from the super class;
b) methods in super class need to use final keyword to prevent override
from subclass;
c) variable name needs to start from a lower case letter.
Now, a new question arises, I'm trying to use abstract method, speed,
in this case.
Definition at the super class level,
// abstract class, abstract method; declare at the supper class level
but implemented at each subclass
abstract public void speed();
Definition at a subclass level,
public void speed() {
// javax.swing.JOptionPane.showMessageDialog(null, "30 mph", "Dog
Speed", 1);
System.out.println("30 mph");
}
Attempt to call the speed method in the Dog class (from the super
class):
public static void main(String[] args) {
Dog pet = new Dog();
System.out.println(pet.speed());
};
The above attempt failed, err msg:
"MammalClass.java": 'void' type not allowed here at line 24, column 33
Any idea what's happening? Many thanks.