Option A and B will compile because protected and transient are legal variable modifiers. Option D will compile because volatile is a proper variable modifier.
Option A, B, D, and E are wrong because protected are the wrong access modifiers, and final, static, and volatile are modifiers but not access modifiers.
(B) and (C) are incorrect because interface variables cannot be either protected or transient. (D) is incorrect because interface methods cannot be final or static.
public class Outer { public void someOuterMethod() { //Line 5 } public class Inner { } public static void main(String[] argv) { Outer ot = new Outer(); //Line 10 } }
Option B gives error - non-static variable cannot be referenced from a static context.
Option C package ot does not exist.
Option D gives error - non-static variable cannot be referenced from a static context.
class A { protected int method1(int a, int b) { return 0; } }
Option B is wrong - because it can't override as there are less access privileges in the subclass method1.
Option C is wrong - because to override it, the return type needs to be an integer. The different return type means that the method is not overriding but the same argument list means that the method is not overloading. Conflict - compile time error.
Option D is wrong - because you can't override a method and make it a class method i.e. using static.
Option A and C are wrong because public and protected are less restrictive. Option B and D are wrong because abstract and synchronized are not access modifiers.
(1) is wrong because a class cannot be abstract and final?there would be no way to use such a class. (2) is wrong because interfaces and classes cannot be marked as static. (4) and (5) are wrong because classes and interfaces cannot be marked as protected.
(1), is incorrect because an interface method must be public; if it is not explicitly declared public it will be made public implicitly. (4) is incorrect because interface methods cannot be static.
Option (3) is not a correct array declaration. The compiler complains with: illegal start of type. The brackets are in the wrong place. The following would work: public int[ ] a
Option (4) is not a correct array declaration. The compiler complains with: ']' expected. A closing bracket is expected in place of the 3. The following works: private int a []
Option (5) is not a correct array declaration. The compiler complains with 2 errors:
']' expected. A closing bracket is expected in place of the 3 and
<identifier> expected A variable name is expected after a[ ] .
Copyright ©CuriousTab. All rights reserved.