On May 29, 9:52 am, [email protected] wrote:
> Hi all
> I tried create following:
> Person[] myPerson=new Person[3];
> myPerson[0]=new Person();
> myPerson[1]=new Employee();
> myPerson[2]=new Manager();
>
> but myPerson[1] have not methods and attributes of the Employee class
> myPerson[2] have not also methods and attributes of the Manager class

Since Employee and Manager are children (or extensions) of Person, it
is possible to make references to them by their parent class, thanks
to polymorphism,  BUT you'll have to manually and correctly cast them
in order to access the methods and accessors of their respective
classes.

You could do something like:
((Employee)myPerson[1]).methodSomething();

You could verify by using the isInstance method or just run the
program and see if it generates a bad cast exception :]

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to