Tuesday, February 19, 2013

Quiz Inheritance Corrections

Example 1:

Consider the following class definitions.
public class A{
private int a1;
public void methodA() {
methodB();          // Statement I
}
}
public class B extends A {
public void methodB() {
methodA();          // Statement II
a1 = 0;             // Statement III
}
}
Which of the labeled statements in the methods shown above will cause a compile-time error?


II and III
exact_answernone8514

III only
exact_answernone9197
I and II
exact_answernone8885
I and III
 
EXPLANATION:
I think a1 is declared as a private int in class A, so when class B extends A, it does not need to re-assign it to 0. I'm actually  not sure if this is the real reason, but that's what I'm going with for now. When it does this, it causes a compile-time error. methodB() will also cause this error because it is not defined.
 
exact_answernone6792
 Example 2:

true_false_question 26865425
A subclass of an abstract class must always implement every defined abstract method.
exact_answernone238
 
False

 EXPLANATION:
If the subclass is also an abstract class, it does not need to implement the abstract methods.



















 

No comments:

Post a Comment