Packages And Access Modifiers

11.Which access modifier provides the least restrictive access?
  • A. public
  • B. protected
  • C. default
  • D. private

public

public

12.Which of the following is true about sub-packages in Java?
  • A. A sub-package automatically inherits access to members of the parent package.
  • B. Sub-packages are just nested folders with package declarations.
  • C. Sub-packages are created with a special keyword.
  • D. All classes in a sub-package are automatically imported.

Sub-packages are just nested folders with package declarations.

Sub-packages are just nested folders with package declarations.

13. If a class A is in package p1 and class B is in package p2, which access modifier allows B to access a member in A?
  • A. default
  • B. private
  • C. protected (if B extends A)
  • D. protected (without inheritance)

protected (if B extends A)

protected (if B extends A)

14. How does Java resolve class name conflicts when two imported packages contain the same class name?
  • A. Java automatically chooses the one declared first.
  • B. Java raises a compilation error.
  • C. The fully qualified name must be used.
  • D. Java randomly picks one.

The fully qualified name must be used.

The fully qualified name must be used.

15.What is the output?
package test; public class A { protected void display() { System.out.println("A"); } } package demo; import test.A; public class B extends A { public static void main(String[] args) { B b = new B(); b.display(); } }
  • A. Compile Error
  • B. A
  • C. Runtime Error
  • D. B

A

A