Using ________ before a variable will restrict its visibility to the same class only.

  • package-private (default)
  • private
  • protected
  • public
In Java, when you declare a variable as "private," it restricts its visibility to the same class only. This means that the variable can only be accessed within the class where it is declared and is not accessible from outside classes. It is a crucial concept for data hiding and encapsulation.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *