Hi,
This maybe explained this way:
class Person implements DadInterface, DoctorProfessionalInterface,
FootballInterface {
}
So, any instance of Person can be casted to DadInterface,
DoctorProfessionalInterface, FootballInterface. In other way, you may
find metholds, avariables, and something like that of the three
interfaces in class Person field.
And, the difference between person2, dad1, and person3 is:
person2 uses part of FootballInterface ; although person2 can be
casted to Person explicitly to use other parts.
dad1 uses part of DadInterface; although dad1 can be casted to Person
explicitly to use other parts.
persons uses all parts.
This maybe more directly to be understanding.
Regards,
Joseph
On Feb 27, 10:26 pm, Tanya Dina Ruttenberg <[email protected]>
wrote:
> Thanks Keith. But I still don't really get it.
> Suppose I have a class Person which implements several interfaces. My person
> class is a Dad and a doctor and likes
> to play football on weekends.
> class Person implements DadInterface, DoctorProfessionalInterface,
> FootballInterface {
> }
> In my program I set up 3 objects like these:
> FootballInterface person2 = new Person();
> DadInterface dad1 = new Person();
> Person person3 = new Person();
> What is the difference between person2, dad1, and person3? Don't they have
> all the same properties and
> methods as any Person()?
> Feb 26, 2009 10:49:55 PM,[email protected]:Tanya,
>
>
>
> An interface is a way to abstract. Interface is more a design than an
> implementation. You can use Interfaces to handle different typed objects. In
> the case below it is true that type declaring as a class works but is not
> recommened. I think this is because the class Person implements the
> PersonInterface. For someone to look at and maintain the code they might
> think that "pc" was an abstract class and not an interface. So simply
> declaring an object "pi" of type PersonInterface and object class Person
> makes sense.
>
>
>
> It makes more sense once you implment more than one interface or multiple
> interfaces. So think of Person implementing multiple interfaces and the type
> PersonInterface declaration makes more sense. In general it seems to me that
> if there are multiple interfaces for a class to inherit, that is when we use
> interface and not just class. I also read somewhere that if you create an
> abstract class with all the methods abstract, that is really an interface.
>
>
>
> Keith
>
> From:Tanya Dina Ruttenberg
> <[email protected]>To:[email protected]:Thursday,
> February 26, 2009 2:48:29 PMSubject:[java programming] Interfaces lesson -
> question
> Inhttp://www.javapassion.com/javase/javainterface.pdfpage 21 it says
> Interfaces and classes are both types
> – This means that an interface can be used in places
> where a class can be used
> – For example:
> // Recommended practice <<----
> PersonInterface pi = new Person(); <<----
> // Not recommended practice <<----
> Person pc = new Person(); <<----
> Why would it be the recommended practice to type a new object by its
> interface name?
> Tanya
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---