Site navigation

In Java, what is the purpose of the 'public' keyword in a class declaration?

Question and options

In Java, what is the purpose of the 'public' keyword in a class declaration?
  1. It indicates that the class is publicly accessible from any package
  2. It specifies that the class is private and can only be accessed within its own package
  3. It declares a public method within the class
  4. It is not a valid keyword in class declarations

Answer and explanation

Correct answer: A - It indicates that the class is publicly accessible from any package
A public top-level class is accessible from classes in any package. Without public it is package-private.

Practice for these exams

  • CUSAT CAT M.Sc. Forensic Science

  • Uttarakhand Judicial Services

    Subject revision

Related question papers

Related exam syllabi

More solved explanations in Computer fundamentals