Dear All,
I have been learning
Java for a while now and I have run a few successful snippets on inheritance using extends keyword. But suddenly now I get the following error on running the subclass. This is a sample picked up from the java site directly. Could some one tell me what I am doing wronog? I am using textpad and j2sdk1.4.2_04
D:\RND\java\Cat.java:1: cannot resolve symbol
symbol : class Animal
location: class Cat
public class Cat extends Animal {
^
D:\RND\java\Cat.java:11: cannot resolve symbol
symbol : class Animal
location: class Cat
Animal myAnimal = myCat;
^
D:\RND\java\Cat.java:13: cannot resolve symbol
symbol : variable Animal
location: class Cat
Animal.hide(); //Better!
^
3 errors
Tool completed with exit code 1
//------------Base class
public class Animal {
public static void hide() {
System.out.println("The hide method in Animal.%n");
}
public void override() {
System.out.println("The override method in Animal.%n");
}
}
//------------Sub Class
public class Cat extends Animal {
public static void hide() {
System.out.println("The hide method in Cat.%n");
}
public void override() {
System.out.println("The override method in Cat.%n");
}
public static void main(
String[] args) {
Cat myCat = new Cat();
Animal myAnimal = myCat;
myAnimal.hide(); //BAD STYLE
Animal.hide(); //Better!
myAnimal.override();
}
}
Please tell me what is wrong and why I am getting an error.
Regards
Uday