Рассмотрим следующее:
public class OuterClass {
static class NestedClass extends AbstractList<List<Integer>> {
void add(/* parameters here */) {
// note this method is not declared public
// print here does NOT appear in output
// implementation details here
}
public int size() {
// print here appears in output
// implementation details here
}
public List<Integer> get(int index) {
// print here appears in output
// implementation details here
}
}
public static List<List<Integer>> method(/* parameters here */) {
NestedClass nc = new NestedClass();
nc.add(..);
}
}
Затем в отдельном методе я создаю экземпляр NestedClass
. Когда я запускаю код, даже не вызывая get
или size
, операторы вывода появляются в выходных данных. Как / почему это происходит? Я понимаю, что get
и size
необходимы, поскольку AbstractList
расширен, но я никогда не вызываю size
или get
.
В общем, если B
расширяет A
, любой вызов метода B
по своей природе вызовет переопределенные абстрактные методы, реализованные в B
?
Спасибо