Multiple choice technology programming languages

Can two classes contain member functions with the same name?

  1. No

  2. Yes, but only if the two classes have the same name

  3. Yes, but only if the main program does not declare both kinds

  4. Yes, this is always allowed

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Yes, class definitions establish independent namespaces and scopes. Two entirely different classes are fully allowed to declare member functions with the exact same name and signature without causing compiler conflicts. This is a fundamental aspect of encapsulation and object-oriented design.