Results 1 to 2 of 2
Thread: Interfaces
- 11-19-2010, 04:05 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 26
- Rep Power
- 0
Interfaces
Hi, I'm having a lot of trouble understanding interfaces in java. In my uni assignment, I essentially have to create a registration thing for a bunch of vehicles and I have to make 3 interface classes (each symbolizing 3 different types of vehicles... motor bikes, commercial vehicles, and private vehicles) and all of those are derived classes of the base class "vehicle".
Then I need a registration class which implements all 3 of those classes.
The thing which confuses me though is all this abstraction with interface classes.
Am I correct in saying that every single method you have within an interface class, can't have a body? What is the point of that? Wouldn't that mean I would have to implement all three original interface classes and write out the method bodies within the registration class anyways? Wouldn't it just be easier not to have the 3 other classes.
I guess what I am asking is, can someone just tell me the point of interface classes.. I'm reading all this material on them, and it just seems as though it tells me how to do them, but I just don't see the point...
THANKS!
- 11-19-2010, 05:46 PM #2
Senior Member
- Join Date
- Feb 2009
- Posts
- 312
- Rep Power
- 13
I have seen interfaces used 2 ways.
The first is the way it was designed for: Providing a Frame work for other classes to implement, which allows you to handle just the interface and not the various objects. A good example would be the java.util.List interface(List (Java 2 Platform SE 5.0)). You can choose just to code for a List object.
Java Code:List list = getList(); list.add(object1); list.add(object2);
The second way of using Interfaces would be a resting place for global constants. You can list all the constants inside an interface class and have the classes that need to use them just implement the interface.
Java Code:public interface IConstants { public static final String LIBRARY = "library"; public static final int TYPE_INT = 0; public static final int TYPE_DOUBLE = 1;
Similar Threads
-
Interfaces (not GUI)
By guilty in forum Advanced JavaReplies: 1Last Post: 11-05-2010, 08:16 PM -
Interfaces
By justin1980 in forum New To JavaReplies: 9Last Post: 02-10-2010, 01:04 PM -
Interfaces
By computerquip in forum New To JavaReplies: 19Last Post: 09-08-2009, 05:58 PM -
Interfaces
By jon80 in forum New To JavaReplies: 2Last Post: 05-03-2008, 10:57 PM -
Interfaces
By imran_khan in forum New To JavaReplies: 5Last Post: 07-30-2007, 09:11 AM
Bookmarks