Can a subclass constructor directly access the private variables of its superclass?

  • No
  • Only if they are static
  • Only if they have the same name
  • Yes
No, a subclass constructor cannot directly access the private variables of its superclass. Private variables are not visible to subclasses, so they cannot be accessed or modified directly. Instead, you can use setter and getter methods or make the superclass variables protected or package-private (default) if you need subclass access.
Add your answer
Loading...

Leave a comment

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