Given the following source code, which comment line can be uncommented without introducing errors?.
abstract class MyClass { abstract void f(); final void g() {} //final void h() {} // (1) protected static int i; private int j; } final class MyOtherClass extends MyClass { //MyOtherClass(int n) { m = n; } // (2) public static void main(String[] args) { MyClass mc = new MyOtherClass(); }// w w w. j a v a 2 s. co m void f() {} void h() {} //void k() { i++; } // (3) //void l() { j++; } // (4) int m; }
Select the one correct answer.
(c)
The line void k()
{ i++; } can be re-inserted without introducing errors.
Re-inserting line (1) will cause the compilation to fail, since MyOtherClass
will try to override a final method.
Re-inserting line (2) will fail, since MyOtherClass
will no longer have a default constructor.
The main()
method needs to call the default constructor.
Reinserting line (3) will work without any problems, but re-inserting line (4) will fail, since the method will try to access a private member of the superclass.