Question Details

No question body available.

Tags

uml

Answers (1)

Accepted Answer Available
Accepted Answer
August 6, 2025 Score: 3 Rep: 82,537 Quality: Expert Completeness: 80%

The book is for language lawyers. And the exercises shall prepare you for the certification exam. As for many of those, you need to be very careful about the wording.

The answer

Add a “−” to precede Y to make z privately visible

is wrong, because adding “−” to precede Y does not make z privately visible: it makes Y privately visible. Any other class in P1 could still see Y and hence z, because z is still publicly visible in Y.

-Y may solve the initial problem as you pointed out, but certainly not because it makes z private !

The answer

Add a “−” to precede P1 to make P1 privately visible

Is correct. First the notation -P1 really means that P1 is privately visible. Then it is legitimate to make P1 privately visible. Then the consequence:

A Named Element with public visibility is visible to all elements that can access the contents of the Namespace

A NamedElement with private visibility is only visible inside the Namespace that owns it.

My understanding is that:

  • P1 is not visible to classes of other packages (since they are in the namespace of that other package and not in the namespace that owns P1). For other packages to access P1 public content, an import would be required.

  • P1 would be visible classes that are at the top level. But this seems not to allow properties and operations of those classes to access to P1 because they are again in the namespace defined by that top level class and not the enclosing namespace that owns P1 and the class. I agree that this is far-fetched and not fully complies with the expectations.

And I recognise that this is a very rigid interpretation (and not aligned with semantics of popular programming language). In my view, the best option would have been to make Y package visible. But this option is not proposed in the book (they only mention a false alternative of ~P1 which is not legitimate as package cannot have package visibility).