adplus-dvertising
frame-decoration

Question

An Employee class has a property called age and emp is reference to a Employee object and we want the statement Console.WriteLine(emp.age) to fail. Which of the following options will ensure this functionality?

a.

Declare age property with only get accessor.

b.

Declare age property with only set accessor.

c.

Declare age property with both get and set accessors.

d.

Declare age property with get, set and normal accessors.

Posted under C# programming

Answer: (b).Declare age property with only set accessor.

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. An Employee class has a property called age and emp is reference to a Employee object and we want the statement Console.WriteLine(emp.age) to fail. Which of the following options...

Similar Questions

Discover Related MCQs

Q. Which of the following is NOT a .NET Exception class?

Q. Which of the following statements is correct about an Exception?

Q. In C#.NET if we do not catch the exception thrown at runtime then which of the following will catch it?

Q. Which of the following is the Object Oriented way of handling run-time errors?

Q. Exceptions can be thrown even from a constructor, whereas error codes cannot be returned from a constructor.

Q. All code inside finally block is guaranteed to execute irrespective of whether an exception occurs in the protected block or not.

Q. Which of the following is NOT an Exception?

Q. It is compulsory for all classes whose objects can be thrown with throw statement to be derived from System.Exception class.

Q. Which of the following statements is true about an enum used in C#.NET?

Q. An enum that is declared inside a class, struct, namespace or interface is treated as public.

Q. An enum can be declared inside a class, struct, namespace or interface.

Q. Which of the following CANNOT be used as an underlying datatype for an enum in C#.NET?

Q. Which of the following statements is correct about an enum used in C#.NET?

Q. Choose the correct statement among the followings?

Q. Choose the keyword which declares the indexer?

Q. Choose the operator/operators which is/are not used to access the [] operator in indexers?

Q. Choose the correct statement among the following?

Q. Which among the following are the advantages of using indexers?

Q. Choose the correct statement about properties describing the indexers?

Q. Choose the correct alternative that utilizes the indexed property such that a group named class has indexed property which stores or retrieves value to/from an array of 5 numbers?