Hi dhana, When you create the array of the animal class in the first line of the main, all the elements are upcasted to the animal class. In order to use your method (method1) you should explicitly downcast a (i.e. the formerly upcasted dog object) by doing: ((dog)a).method1(); Gian Franco
You didnt define method1 in either animal or pet so what would you expect?
SCJP 1.4<br />SCWCD 1.4
Joined: Oct 01, 2003
hi Gian franco
I got it now.Thanx for ur help
Joined: Dec 16, 2003
Hi dhana, Coming back to your question. If polymorphism is desired the base class animal should provide the common interface to the derived classes. The subclasses should override these definitions to provide unique behavior for each specific type of animals. Not defining the methods in the base class or giving them a private access specifier inhibits polymorphism. Gian Franco