Questions for: Declarations And Access Control
Option B generates a compiler error: <identifier> expected. The compiler thinks you are trying to create two arrays because there are two array initialisers to the right of the equals, whereas your intention was to create one 3 x 3 two-dimensional array.
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} };
- protected abstract void m1();
- static final void m1(){}
- synchronized public final void m1() {}
- private native void m1();
All the given statements are legal declarations.
Discuss About this Question.
default access is the "package oriented" access modifier.
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.
Discuss About this Question.
public class Test { }
What is the prototype of the default constructor?
Option A and B are wrong because they use the default access modifier and the access modifier for the class is public (remember, the default constructor has the same access modifier as the class).
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.
Discuss About this Question.
- public int a [ ]
- static int [ ] a
- public [ ] int a
- private int a [3]
- private int [3] a [ ]
- public final int [ ] a
(1), (2) and (6) are valid array declarations.
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[ ] .
Discuss About this Question.
Discuss About this Question.