Bird
0
0

You have a class with a private field and want to allow read access only within the same assembly but not outside. Which access modifiers should you use for the field and a method to read it?

hard🚀 Application Q8 of 15
C Sharp (C#) - Classes and Objects
You have a class with a private field and want to allow read access only within the same assembly but not outside. Which access modifiers should you use for the field and a method to read it?
Aprivate field, internal method
Binternal field, public method
Cprivate field, public method
Dpublic field, private method
Step-by-Step Solution
Solution:
  1. Step 1: Restrict field access

    Field should be private to hide it from outside classes.
  2. Step 2: Allow read access within assembly

    Method to read field should be internal to allow access only inside assembly.
  3. Final Answer:

    private field, internal method -> Option A
  4. Quick Check:

    Private field + internal method = read access inside assembly [OK]
Quick Trick: Use private field + internal method for assembly-only read [OK]
Common Mistakes:
MISTAKES
  • Making field internal exposes it too much
  • Using public method allows access everywhere
  • Confusing internal and private roles

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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