Given the following classes and declarations, which statements are true?.
// Classes//w ww. j a v a 2 s .c o m class MyBaseClass { private int i; public void f() { /* ... */ } public void g() { /* ... */ } } class Main extends MyBaseClass { public int j; public void g() { /* ... */ } } // Declarations: MyBaseClass a = new MyBaseClass(); Main b = new Main();
Select the three correct answers.
f()
; is legal.g()
; is legal.(a), (b), and (d)
Main is a subclass of MyBaseClass that overrides the method g()
.
The statement a.j = 5 is not legal, since the member j in the class Main cannot be accessed through a MyBaseClass reference.
The statement b.i = 3 is not legal either, since the private member i cannot be accessed from outside of the class MyBaseClass.