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[ ] .
(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.
(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.
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.
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.
(2) causes a compiler error ( '{' expected ) because the array constructor does not specify the number of elements in the array. The following is the correct syntax: float f2[ ] = new float[3];
(3), (4), and (5) compile without error.
public class Test { }
Option D is wrong. The void makes the compiler think that this is a method specification - in fact if it were a method specification the compiler would spit it out.
To correct the problem and make option B compile you need to add an extra pair of curly brackets:
int [ ] [ ] scores = { {2,7,6}, {9,3,45} };
interface Base { boolean m1 (); byte m2(short s); }
(1) is incorrect because interfaces don't implement anything. (2) is incorrect because classes don't extend interfaces. (5) is incorrect because interface methods are implicitly public, so the methods being implemented must be public.
Comments
There are no comments.Copyright ©CuriousTab. All rights reserved.