Java Declarations and Access Control Quiz
Java Declarations and Access Control Quiz
Questions
You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?
- public
- protected
- private
- transient
What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package?
- public
- abstract
- protected
- synchronized
- default access
Which cause a compiler error?
- int[ ] scores = {3, 5, 7};
- int [ ][ ] scores = {2,7,6}, {9,3,45};
- String cats[ ] = {"Fluffy", "Spot", "Zeus"};
- boolean results[ ] = new boolean [] {true, false, true};
You want a class to have access to members of another class in the same package. Which is the most restrictive access that accomplishes this objective?
- public
- private
- protected
- default access
Which one creates an instance of an array?
- int[ ] ia = new int[15];
- float fa = new float[20];
- char[ ] ca = "Some String";
- int ia[ ] [ ] = { 4, 5, 6 }, { 1,2,3 };
Which of the following class level (nonlocal) variable declarations will not compile?
- protected int a;
- transient int b = 3;
- private synchronized int e;
- volatile int d;
Given a method in a protected class, what access modifier do you use to restrict access to that method to only the other members of the same class?
- final
- static
- private
- protected
Which is a valid declaration within an interface?
- public static short stop = 23;
- protected short stop = 23;
- transient short stop = 23;
- final void madness(short stop);