Question
a.
Declare rollNo property with both get and set accessors.
b.
Declare rollNo property with only set accessor.
c.
Declare rollNo property with get, set and normal accessors.
d.
Declare rollNo property with only get accessor.
Posted under C# programming
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. A Student class has a property called rollNo and stu is a reference to a Student object and we want the statement stu.RollNo = 28 to fail. Which of the following options will...
Similar Questions
Discover Related MCQs
Q. Which of the following statements are correct?
1. The signature of an indexer consists of the number and types of its formal parameters.
2. Indexers are similar to properties except that their accessors take parameters.
3. Accessors of interface indexers use modifiers.
4. The type of an indexer and the type of its parameters must be at least as accessible as the indexer itself.
5. An interface accessor contains a body.
View solution
Q. Which of the following is the correct way to implement a write only property Length in a Sample class?
View solution
Q. If a Student class has an indexed property which is used to store or retrieve values to/from an array of 5 integers, then which of the following are the correct ways to use this indexed property?
1.
Student[3] = 34;
2.
Student s = new Student();
s[3] = 34;
3.
Student s = new Student();
Console.WriteLine(s[3]);
4.
Console.WriteLine(Student[3]);
5.
Student.this s = new Student.this();
s[3] = 34;
View solution
Q. If Sample class has a Length property with set accessor then which of the following statements will work correctly?
View solution
Q. If Sample class has a Length property with get accessor then which of the following statements will work correctly?
View solution
Q. Suppose a Student class has an indexed property. This property is used to set or retrieve values to/from an array of 5 integers called scores[]. We want the property to report "Invalid Index" message if the user attempts to exceed the bounds of the array. Which of the following is the correct way to implement this property?
View solution
Q. Which of the following statements is correct about properties used in C#.NET?
View solution
Q. Which of the following is the correct way to implement a read only property Length in a Sample class?
View solution
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 will ensure this functionality?
View solution
Q. Which of the following is NOT a .NET Exception class?
View solution
Q. Which of the following statements is correct about an Exception?
View solution
Q. In C#.NET if we do not catch the exception thrown at runtime then which of the following will catch it?
View solution
Q. Which of the following is the Object Oriented way of handling run-time errors?
View solution
Q. Exceptions can be thrown even from a constructor, whereas error codes cannot be returned from a constructor.
View solution
Q. All code inside finally block is guaranteed to execute irrespective of whether an exception occurs in the protected block or not.
View solution
Q. Which of the following is NOT an Exception?
View solution
Q. It is compulsory for all classes whose objects can be thrown with throw statement to be derived from System.Exception class.
View solution
Q. Which of the following statements is true about an enum used in C#.NET?
View solution
Q. An enum that is declared inside a class, struct, namespace or interface is treated as public.
View solution
Q. An enum can be declared inside a class, struct, namespace or interface.
View solution
Suggested Topics
Are you eager to expand your knowledge beyond C# programming? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!