CS FundamentalsEasyHCL · Tech Mahindra pattern

A class diagram shows Employee with attribute `- salary: double` and operation `+ getSalary(): double`. What do the leading `-` and `+` symbols indicate?

  1. A. `-` marks salary as private (accessible only within Employee), and `+` marks getSalary() as public (accessible from any class)
  2. B. `-` means the attribute is optional and `+` means the method is static
  3. C. `-` means the attribute is abstract and `+` means it is final
  4. D. They indicate the order attributes were added to the class

Correct answer: A. `-` marks salary as private (accessible only within Employee), and `+` marks getSalary() as public (accessible from any class)

UML visibility notation: `-` private, `+` public, `#` protected, `~` package. Here salary is hidden behind the public getSalary() accessor, a standard encapsulation pattern.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic