Search code examples
javaooppackageprivate

Can a subclass access a superclass' private members?


In Java, class A defines a member variable private int num; Class B is a subclass of class A.

1- If the two classes are in the same package - does B inherit num?

2- If the two classes are not in the same package - does B inherit num?


Solution

  • B does not inherit or have access to num in either of those cases.