wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interface" Watch "Interface" New topic
Author

Interface

Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Dear all, i have a question from a mock exam
Which of these statement about interface are true?
Select 3 correct answer
a. Interfaces permit multiple implementation inharitance
b. Unlike a clas, an interface can extend from multiple interfaces
c. Members of an interface are never static
d. Members of an interface may be static
e. Interfaces cannot be final
The answer is b, d, e
Can you help me why b is true?
daniel
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
From JLS 9.1.2 Superinterfaces and Subinterfaces

If an extends clause is provided, then the interface being declared extends each of the other named interfaces and therefore inherits the member types, methods, and constants of each of the other named interfaces. These other named interfaces are the direct superinterfaces of the interface being declared. Any class that implements the declared interface is also considered to implement all the interfaces that this interface extends.

in clear:
interface A{}
interface B{}
interface C extends A,B{}
is perfectly legal.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Brian Lugo
Ranch Hand

Joined: Nov 10, 2000
Posts: 165
I know there are only three correct answers to this question, but what is wrong with the choice a.
Thanks,
Brian
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
interface do not provide multiple implementation inheritance since interfaces do not contain any implementation.
Java is based upon single implementation inheritance, that is, a class is allowed to directly subclass only one class at a time (unlike in C++). However, multiple interface inheritance is allowed as described in the JLS sections posted above.
[ March 13, 2002: Message edited by: Valentin Crettaz ]
Brian Lugo
Ranch Hand

Joined: Nov 10, 2000
Posts: 165
I got it - Thanks a lot Val!
Brian
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Just one more thing:
consider the following code:

By looking at this code, one might wonder why multiple interface inheritance works and may ask him/herself "but which one of the methodA gets executed?". Well, since interfaces do not contain any implementation, interface methods are not executed. Interface methods must be implemented by implementing classes (here Test). Paragraph 8.4.6.4 Inheriting Methods with the Same Signatureexplains what happens when several methods having the same signature are inherited from multiple interfaces. Remember that interface methods are implicitely abstract, and if your class (Test) is not abstract it does necessarly mean that it overrides (and implements) the methods (methodA) it inherits from its superinterfaces (A and B), thus the problem is solved.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Interface
 
Similar Threads
interface
Interface question from Khalid and Rasmussen
Inheritance
Interface Ques