Hey Miga!

Thanks for your response.  I'll have to search the forum, as I'm still not
any more clear on the subject.  It seems to me that a Manager would, by
definition, also be seen as a Person.  If you're saying that this is more
useful when you've got a class hierarchy that's more than one parent and one
child, I'm starting to get it, I'm just still not 100% sure why.

Thanks!

Cheers,

-m

On Wed, Apr 1, 2009 at 1:40 PM, miga <migat...@gmail.com> wrote:

>
>
>
> On Apr 1, 10:26 pm, "maa...@gmail.com" <maa...@gmail.com> wrote:
> > Hi All,
> >
> > I apologize if this question has been answered, but I've read all the
> > lessons and supporting material (up to "inner class," at least) and I've
> > spoken to a colleague who has taken a similar intro to Java class, but I
> > still can't figure this out.
> >
> > My question is this:  I know that it's possible to do have a simple class
> > hierarchy like this:
> >
> > Animal
> > -----Dog
> >
> > And to create an object like this:
> >
> > Animal dog1 = new Dog();
> >
> > But I'm curious as to why you would do that when you can just write:
> >
> > Dog dog1 = new Dog();
> >
> > because it seems like either way the compiler would know that a Dog
> object
> > is a subclass of Animal, right?  Is it partially for code readability?
> >
> > Can anyone give me an example of where you'd want to use one method over
> the
> > other, and what the benefits (e.g. performance) might be when using one
> > method over the other?
> You may search the forum, this question has been answered recently in
> great details.
> However, here is a reason why you may want to use the superclass to
> define an instance.
> Say you have a set of person, that is a Person class. Now you have a
> set of managers, that is a Manager class. Obviously Manager is a
> subclass of Person. Now you have a set of employees, that is an
> Employee class. Employee is also obviously a subclass of Person. And
> seeing from the point of view of the Entreprise (a new class), a
> manager -aka an instance of the Manager class) is also an employee (an
> instance of the Employee class).
> But you cannot say directly Brian is a Manager and an Employee; as
> with Dog dog1 = new Dog(), on the contrary you may say: Person brian =
> new Manager(), that's just a way to make brian viewed as a person who
> is also a manager; and as he is a person, you may thereafter view him
> as an employee.
>
> >
>


-- 
Love is a snowmobile racing across the tundra and then suddenly it flips
over, pinning you underneath. At night, the ice weasels come.

- Matt Groening

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

Reply via email to