Given the following classes and declarations,
which of these statements about // 1 and //2 are true?
class MyBaseClass { private int i = 10; public void f (){} public void g (){} } class MyClass extends MyBaseClass { public int i = 20; public void g (){} } public class C{ MyBaseClass a = new MyBaseClass ();//1 MyBaseClass b = new MyClass ();//2 }
Select 1 option
Correct Option is : E
For Option A.
Since variable b is declared as of class MyBaseClass, you cannot do b.i even if the actual object is of class MyClass because i in MyBaseClass is private.
For Option B.
class MyBaseClass has f () so b .f () is legal.
For Option C.
Since variable b is declared as of class MyBaseClass, you cannot do b.i even if the actual object is of class MyClass because i in MyBaseClass is private.