Java Declarations and Access Control Quiz

Java Declarations and Access Control Quiz

8 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?

  1. public
  2. protected
  3. private
  4. transient
Question 2 Multiple Choice (Single Answer)

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?

  1. public
  2. abstract
  3. protected
  4. synchronized
  5. default access
Question 3 Multiple Choice (Single Answer)

Which cause a compiler error?

  1. int[ ] scores = {3, 5, 7};
  2. int [ ][ ] scores = {2,7,6}, {9,3,45};
  3. String cats[ ] = {"Fluffy", "Spot", "Zeus"};
  4. boolean results[ ] = new boolean [] {true, false, true};
Question 4 Multiple Choice (Single Answer)

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?

  1. public
  2. private
  3. protected
  4. default access
Question 5 Multiple Choice (Single Answer)

Which one creates an instance of an array?

  1. int[ ] ia = new int[15];
  2. float fa = new float[20];
  3. char[ ] ca = "Some String";
  4. int ia[ ] [ ] = { 4, 5, 6 }, { 1,2,3 };
Question 6 Multiple Choice (Single Answer)

Which of the following class level (nonlocal) variable declarations will not compile?

  1. protected int a;
  2. transient int b = 3;
  3. private synchronized int e;
  4. volatile int d;
Question 7 Multiple Choice (Single Answer)

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?

  1. final
  2. static
  3. private
  4. protected
Question 8 Multiple Choice (Single Answer)

Which is a valid declaration within an interface?

  1. public static short stop = 23;
  2. protected short stop = 23;
  3. transient short stop = 23;
  4. final void madness(short stop);