Packages And Access Modifiers

6.Which of the following access levels restricts method visibility the most?
  • A. public
  • B. private
  • C. default
  • D. protected

private

private

7. A protected method is accessible in which of the following?
  • A. Only in its own class
  • B. In its own package and subclasses in other packages
  • C. Only in its own package
  • D. Everywhere

In its own package and subclasses in other packages

In its own package and subclasses in other packages

8.Which of the following will cause a compilation error?
  • A. Defining a class inside a package
  • B. Using import without a package declaration
  • C. Importing the same class multiple times
  • D. Declaring a top-level class as private

Declaring a top-level class as private

Declaring a top-level class as private

9.What is the use of the import keyword?
  • A. To access private members of a class
  • B. To include native libraries
  • C. To refer to classes from another package
  • D. To compile multiple classes

To refer to classes from another package

To refer to classes from another package

10.Which of these is not a valid import statement?
  • A. import java.util.Scanner;
  • B. import java.io.*;
  • C. import java.util;
  • D. import static java.lang.Math.*;

import java.util;

import java.util;