aspose file tools
The moose likes Beginning Java and the fly likes Interface and Multiple inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Interface and Multiple inheritance" Watch "Interface and Multiple inheritance" New topic
Author

Interface and Multiple inheritance

Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
I have a question about interface. For example I have Interface A with two functions: getName() and getAddress(). Than interface B with function getSalary(). Interface B is instance of interface A. Than class Professor that is subclass or instance of interface B.
I did the UML diagram on TogetherJ 4.02. My question is does is legal for class C implement the functions from interface A ((getName() or getAddress()).
Thanks a lot
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
First of all, an interface does not contain any functions. It merely declares what methods a class which implements it must provide. This is an important concept. Interfaces are just about describing behavior, not actually implementing that behavior.
Interfaces are similar to classes in some ways, but very different in others. Interfaces cannot be instantiated, so there is no concept of an interface "subclassing" another one. However, there is a similar concept : extending declarations. So an interface can extend another interface, but not subclass it. In your example, we say interface B extends interface A.
Finally, if class Professor implements interface B it is mandatory for class Professor to provide declarations for every method that interface B delclares (if you intend to instantiate it.) Since B extends A, B inherits those declarations from A, so B contains all it's own method delcaration, PLUS A's. Thus Professor is obligated to provide implementation for all of the declared methods in both A and B, otherwise you must declare it to be abstract.


Rob
SCJP 1.4
Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
Thanks a lot Rob
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interface and Multiple inheritance
 
Similar Threads
plz reply as soon as possible
Difference between object and instance
Help on overiding
HFJ doubt
anonymous class