Results 1 to 6 of 6
Thread: Interfaces
- 07-27-2007, 02:41 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 8
- Rep Power
- 0
- 07-27-2007, 05:53 PM #2levent Guest
Assume that you need your class to inherit from two or more classes. Java's "extends" keyword allowed to be used for only one class. The solution to this is to have one class but multiple interfaces if you need more than one base class. This is implemented like this because it is observed that multiple inheritance (extending from more than one class) has some problems.
- 07-27-2007, 07:13 PM #3
Senior Member
- Join Date
- Jul 2007
- Posts
- 130
- Rep Power
- 0
Just adding, interfaces in most java literature are often considered as a capability to be able to do things, so implementing interfaces doesn't exactly the same as inheriting the method of a superclass, since in an interface, the method does nothing, only declaration in the form of abstract method
Some problem that occur when using multiple inheritance (according to some references), if classA and classB got the same method name test() but do very diffrent things, and then classC inherits both of the class but does not override the method test(), when an instance of classC would call the method test() it would be a problem to decide whether the instance would use the classA's test() or classB's test()
Interface is an abstract class, so the class that implements the interface must override the method that it inherited, thus, preventing the multiple inheritance problem above
Another advantages of using interfaces are the availability to use polymorphism to these classes, even if they don't relate at all
- 07-27-2007, 10:57 PM #4levent Guest
Good description cruxblack. Green reputation is sent ;)
- 07-28-2007, 04:54 AM #5
Senior Member
- Join Date
- Jul 2007
- Posts
- 130
- Rep Power
- 0
Thank u Mr.levent:D
- 07-30-2007, 08:11 AM #6
Member
- Join Date
- Jul 2007
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
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 -
Using interfaces with Delegation
By Java Tip in forum Java TipReplies: 0Last Post: 12-06-2007, 01:49 PM -
Help, someone clear up Interfaces for me
By mathias in forum New To JavaReplies: 1Last Post: 08-06-2007, 02:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks