Skip to content
Sharp

Object-oriented programming · interview question

Why does declaring a class as 'public' in Java change runtime behavior?

Multiple choiceMediumchapter-3-curatedpremiumoopaccess-modifiers-and-visibility
Choose one answer
Answer and explanation

Correct answer

C. The class can be accessed from any other class

Why

Declaring a class as 'public' allows it to be accessed from any other class, regardless of the package it resides in. This makes the class globally accessible, enabling broad use across a project.

Test yourself on Object-oriented programming

A free test with instant, explained results. No account needed.

Start free test
All Object-oriented programming questions →