Have pity on a poor C programmer trying to learn OOP!
Say I have the following code:
<pre>
class Animal
{
public void print(){
System.out.println("I am an animal");
}
}
public class AnimalTest
{ public static void main(
String[] args)
{
Animal a = new Animal();
Object obj = a;
a.print(); //prints "I am an animal"
obj.print(); //fails compile with "cannot resolve symbol"
System.out.println(obj.getClass().getName());
// prints "Animal"
}
</pre>
Here's where I'm confused. Variable "obj" is assigned an "Animal" but I can't call obj.print(). Why not? Doing a "getClass" on obj returns "Animal", so how come obj can't resolve the print() method in Animal?
I'm sure I'm making a basic error here, I'd love to hear a simple explanation!
Martin