Question 7 in Marcus's exam3 Which of the following statements are true? 1) An interface can only contain method and not variables 2) Java does not allow the creation of a reference to an interfacewith the new keyword. 3) A class may extend only one other class and implement only one interface 4) Interfaces are the Java approach to addressing the single inheritancemodel, but require implementing classes to create the functionality ofthe Interfaces. The answer is 4.
I thought Interfaces are the Java approach to addressing the multiple inheritancemodel.Java can't support extending more than one class but it supports implementing more than one interface . Aren't we making multiple inheritance possible through interfaces??? Could somebody please clarify regarding that fourth option in the above question. Thanks.
With interface inheritance you are only inheriting SIGNATURES of methods. You have to do the rest of the work (as in implementing those methods). With class inheritance you inherit all implemented behaviour (methods) from the superclass. As a Lao-Tze-Not said: Interfaces in Java are the "POOR MAN'S MULTIPLE CLASS INHERITANCE" way of doing that sort of thing.
Tony Alicea Senior Java Web Application Developer, SCPJ2, SCWCD
Joined: Nov 22, 2008
Thanks for your reply tony. But my question is. Isn't the fourth option in the above question suppose to be. Interfaces are the Java approach to addressing the "MULTIPLE INHERITANCE MODEL", but require implementing classes to create the functionality ofthe Interfaces. But instead it says. Interfaces are the Java approach to addressing the "SINGLE INHERITANCE MODEL", but require implementing classes to create the functionality of the Interfaces.
hi I think the wording that marcus used is correct. Interfaces are their in java to address the SINGLE inheritence model, which is there in c++. We are changing our approach by introducing Interfaces. Hope this helps Alkesh
javagirl, What you think/I think/ and the qstn asks are all same. The qstn essentially says this. Java is based on single inheritance class model.A class cannot extend more than one class at a time. (i.e) the extends keyword can be followed by maximum 1 class. So this is considered as a lack in Java and this peoblem is addressed by means of allowing a class to implement more than 1 interface. So the wording of the qstn is ok I think. regds maha anna [This message has been edited by maha anna (edited March 22, 2000).]
Like javagirl, I'd be happier if the question said "multiple" rather than "single" - but I guess it's a matter of perspective : is the glass half full or half empty? Interfaces are the java approach to addressing the difference between the single inheritance model, which Java has, and the multiple inheritance model, which Java does not have, but which many people wanted Java to support in some way.