Given the following method signatures from ArrayList:
boolean add(E e) protected void removeRange(int fromIndexInclusive, int toIndexExclusive) int size()
and given:
import java.util.ArrayList; public class Main extends ArrayList { public static void main(String[] args) { Main m = new Main(); m.add("w"); m.add("x"); m.add("y"); m.add("z"); m.removeRange(1, 3);// ww w .j a va 2s . c om System.out.print(m.size() + " "); Main m2 = new Main2().go(); System.out.println(m2.size()); } } class Main2 { Main go() { Main m2 = new Main(); m2.add("1"); m2.add("2"); m2.add("3"); m2.removeRange(1, 2); return m2; } }
What is the result?
F is correct.
The removeRange()
method is protected and so cannot be accessed from the Main2 class.
The rest of the code is legal.