Results 1 to 5 of 5
Thread: A question on Interfaces.
- 01-27-2012, 11:03 PM #1
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
A question on Interfaces.
This is from the book SAMS Java in 21 Days:
Especially this:Remember that almost everywhere that you can use a class, you can use an interface
instead. For example, you can declare a variable to be of an interface type:
Iterator loop = new Iterator()
When a variable is declared to be of an interface type, it simply means that the object is
expected to have implemented that interface. In this case, because Iterator contains an
object of the type Iterator, the assumption is that you can call all three of the interface’s
methods on that object: hasNext(), next(), and remove().
What does that mean ?Remember that almost everywhere that you can use a class, you can use an interface
instead.
- 01-27-2012, 11:24 PM #2
Re: A question on Interfaces.
If its is referring to an object's datatype, then there is no difference between a class that extends a class or a class that implements an interface. Both techniques will give the class a datatype.
When a method requires an object of a specific datatype, like when adding a listener, that datatype can be given to the object in the two ways.
- 01-27-2012, 11:30 PM #3
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Re: A question on Interfaces.
So if a method requires a type of Interface f, and if my class MyClass is implementing f, that method can get a reference of type MyClass. Is this all that text is saying ?When a method requires an object of a specific datatype, like when adding a listener, that datatype can be given to the object in the two ways.
- 01-27-2012, 11:59 PM #4
Re: A question on Interfaces.
What you say seems correct. I don't know what the author of the text meant.
- 01-28-2012, 12:00 AM #5
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Similar Threads
-
Question on interfaces
By fatabass in forum New To JavaReplies: 16Last Post: 01-23-2012, 02:33 PM -
Interfaces
By computerquip in forum New To JavaReplies: 19Last Post: 09-08-2009, 04:58 PM -
interfaces..
By sireesha in forum New To JavaReplies: 5Last Post: 01-16-2008, 05:52 PM -
Interfaces
By Kavana Krishnappa in forum New To JavaReplies: 7Last Post: 12-11-2007, 04:28 PM -
Interfaces
By imran_khan in forum New To JavaReplies: 5Last Post: 07-30-2007, 08:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks