Exam4Training

Where is v visible?

Consider the following model

Where is v visible?
A . Only inside S
B . Only inside T
C . Only inside S and T
D . Inside the whole P

Answer: C

Explanation:

In UML, visibility of an attribute is determined by the scope of the classifier it belongs to and its visibility markers. The attribute ‘v’ is marked with a ‘-‘ sign, indicating it is private. Being private, it would normally be visible only within the class it is defined in, which is ‘S’ in this case. However, since ‘T’ is a subclass of ‘S’ (as indicated by the generalization relationship, a line with a closed, unfilled arrowhead), it inherits the attribute ‘v’. Therefore, ‘v’ is visible in both ‘S’ and ‘T’.

Option A is incorrect because it does not consider inheritance. Option B is incorrect for the same reason. Option D is incorrect because a private attribute in a class is not visible to the entire package, only to the class itself and its subclasses.

The UML 2.5 specification states that a private member is only accessible within the namespace it is defined (section 7.5.3). Since ‘T’ is within the namespace of ‘S’ due to inheritance, ‘v’ is visible in both.

Exit mobile version