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
III only
I and II
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.
Example 2:
A subclass of an abstract class must always implement every defined abstract method.
False
EXPLANATION:
If the subclass is also an abstract class, it does not need to implement the abstract methods.
No comments:
Post a Comment