Monday, February 8, 2010

True or False: A Java class can inherit methods and data from two or more classes?

Technically, the answer is true, but I believe the question is worded poorly.





class A {


protected a;


public void doA();


}





class B extends A {


protected b;


public void doB();


}





class C extends B {


// I have a and doA() from A and b and doB() from B!!!


}





That said, the question is probably trying to ask about multiple inheritance, which is not a feature of Java.True or False: A Java class can inherit methods and data from two or more classes?
false .


In Java a class can inherit only ONE class ; however, a class can implement many interfaces.True or False: A Java class can inherit methods and data from two or more classes?
False, unless the classes are inherited from each other.

No comments:

Post a Comment