Java MCQ: Which of the following is not a valid access modifier in Java?
Answer:
Explanation:
In Java, the valid access modifiers are private
, protected
, and public
. These modifiers control the visibility of classes, methods, and variables. private
makes a member accessible only within the class it is declared in. protected
allows access within the same package and by subclasses. public
makes a member accessible from any other class.
The internal
modifier is not valid in Java. It is used in some other programming languages, like C#, to indicate that a member is accessible only within the same assembly.
Understanding the proper use of access modifiers is crucial for encapsulating data and controlling access to the components of your code, which helps in maintaining a clean and secure codebase.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html