- What are the four access modifiers and what do they do?
Answer: The four access modifiers and their effect are described here:
private
: This modifier makes a member only visible inside the classinternal
: This modifier makes a member only visible inside the class or within the same assemblyprotected
: This modifier makes a member only visible inside the class or derived classespublic
: This modifier makes a member visible everywhere
- What is the difference between the
static
,const
, andreadonly
keywords?
Answer: The difference between the static
, const
, and readonly
keywords is:
static
: This keyword makes the member shared by all instances and accessed through the typeconst
: This keyword makes a field a fixed literal value that should never changereadonly
: This keyword makes a field that can only be assigned at runtime using a constructor
- What does a constructor do?
Answer: A constructor allocates memory and initializes field values...