Which of the following statement is true about visibility?

  1. UML uses # for public element

  2. UML uses - for private element

  3. UML uses * for protected element

  4. All of the above


Correct Option: B

AI Explanation

To answer this question, you need to understand the UML notation for visibility.

In UML, visibility is used to indicate the accessibility of an element in a class. There are three types of visibility in UML:

  • Public: Denoted by a '+' symbol. It indicates that the element is accessible by all other elements.
  • Private: Denoted by a '-' symbol. It indicates that the element is only accessible within the class where it is defined.
  • Protected: Denoted by a '#' symbol. It indicates that the element is accessible within the class where it is defined, as well as its subclasses.

Let's go through each option to understand why it is correct or incorrect:

Option A) UML uses # for public element - This option is incorrect because UML uses '+' for public elements, not '#'.

Option B) UML uses - for private element - This option is correct because UML uses '-' for private elements. Private elements are only accessible within the class where they are defined.

Option C) UML uses * for protected element - This option is incorrect because UML uses '#' for protected elements, not '*'.

Option D) All of the above - This option is incorrect because UML uses '+' for public elements, not '#'.

The correct answer is B) UML uses - for private element. This option is correct because UML uses '-' to denote that an element is private and can only be accessed within the class where it is defined.

Find more quizzes: