You are abusing the is-a and has-a relationships to the point where it becomes senseless:
class Cow extends Horse// this is saying Cow is a Horse if anything, both classes should extend Animal or FarmAnimal or the like
Why? A horse has legs, tail, ect. Can be ridden, eat, make noises, ect. But has a Cow? Is it freaking out or something?
class Horse extends Objective61 //why extend a class whose only member is main?
The problem Mr. Lynn pointed out is called derived class reference to a base class object. Look this up. You can't do this, because if you could it would have undefined behavior. You can do the converse and is a quite useful tool when used under a inheritance heirarchy that makes sense: Horse horse = new new Cow(); // not implying this makes sense [ June 16, 2006: Message edited by: Rusty Shackleford ]
"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
A Horse is not a Cow. It does not extend Cow, it does not implement Cow, it is not in any way a subclass of Cow. You cannot create a Horse and assign it to a reference variable declared to be a Cow because they are not in any way the same thing.
But it's giving NullPointerException.I already declared a number for tie() method.
Joined: Jan 03, 2006
Where is your reference to an instianted Cow object?
When myHorse is created, myCow is set to null by default, when not explicity created in a explicit constructor.
If a horse and a cow share attributes, they should be in their own class that implements some interface. That way Horse has a <whatever attribute that int is supposed to be>, and not a Cow which makes no sense.
Go back over the whole concept of inheritance and the reasons it is there. [ June 16, 2006: Message edited by: Rusty Shackleford ]