Bird
0
0

Why is it invalid to declare two classes with the same name in the same namespace without using partial or nested classes?

hard🧠 Conceptual Q10 of 15
C Sharp (C#) - Classes and Objects
Why is it invalid to declare two classes with the same name in the same namespace without using partial or nested classes?
ABecause access modifiers prevent duplicate names
BBecause classes cannot have constructors with same name
CBecause only structs can have duplicate names
DBecause class names must be unique within a namespace
Step-by-Step Solution
Solution:
  1. Step 1: Understand class naming rules in namespaces

    Within a namespace, class names must be unique to avoid ambiguity.
  2. Step 2: Confirm why duplicates are invalid

    Declaring two classes with the same name in the same namespace causes a compilation error due to name conflict.
  3. Final Answer:

    Class names must be unique within a namespace -> Option D
  4. Quick Check:

    Unique class names per namespace = true [OK]
Quick Trick: Class names must be unique in the same namespace [OK]
Common Mistakes:
MISTAKES
  • Confusing constructor names with class names
  • Thinking access modifiers allow duplicates
  • Believing structs allow duplicate names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes