Using Interfaces ?
- From: "TonyB" <tonyb@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 25 Feb 2007 09:28:41 GMT
I've started java recently and I'm having some problems using interfaces in
real world cases.
Say I have an interface, "exampleinterface" declaring a list of methods. I
write a class, "example1class" which implements the interface methods 1 for
1. I can compile the class ok since all methods required by the interface
are implemented in the class. I could write another class which also
implements interface "exampleinterface" called "example2class".
Now if I want to use an object of type "example1class" in my code, I create
it using "exampleobject = new example1class" where exampleobject is declared
as type "example1class". Similarly I could use "example2class" also.
But I'm puzzled as to how to create an object that uses the interface
"interfaceexample", and how to specify which of the two possible classes
that implement the interface are actually used in my code ?
Thanks
Tony
.
- Follow-Ups:
- Re: Using Interfaces ?
- From: andrewmcdonagh
- Re: Using Interfaces ?
- From: TonyB
- Re: Using Interfaces ?
- From: Thomas Schodt
- Re: Using Interfaces ?
- Prev by Date: Re: Checking input for letters
- Next by Date: Re: Using Interfaces ?
- Previous by thread: Re: carriage return in hex 0D
- Next by thread: Re: Using Interfaces ?
- Index(es):
Relevant Pages
|
|