Java Programming - Declarations and Access Control
- Declarations and Access Control - General Questions
- Declarations and Access Control - Finding the output
- Declarations and Access Control - Pointing out the correct statements
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.
- protected abstract void m1();
- static final void m1(){}
- synchronized public final void m1() {}
- private native void m1();
All the given statements are legal declarations.
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} };
- private int getArea();
- public float getVol(float x);
- public void main(String [] args);
- public static void main(String [] args);
- boolean setFlag(Boolean [] test);
(2), (3), and (5). These are all valid interface method signatures.
(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.
The only two real contenders are C and D. Protected access Option C makes a member accessible only to classes in the same package or subclass of the class. While default access Option D makes a member accessible only to classes in the same package.