Explore topic-wise MCQs in Attributes .

This section includes 5 Mcqs, each offering curated multiple-choice questions to sharpen your Attributes knowledge and support exam preparation. Choose a topic below to get started.

1.

Which of the folowing does an indexer allow to index in the same way as an array?

A. 1, 3, 5
B. 2, 4
C. 3, 5
D. 3, 4, 5
Answer» B. 2, 4
2.

An Account class has a property called accountNo and acc is a reference to a bank object and we want the C#.NET code snippet given below to work. Which of the following options will ensure this functionality?

A. Declare accountNo property with both get and set accessors.
B. Declare accountNo property with only get accessor.
C. Declare accountNo property with get, set and normal accessors.
D. Declare accountNo property with only set accessor.
Answer» B. Declare accountNo property with only get accessor.
3.

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?

A. 1, 2
B. 2, 3
C. 3, 4
D. 3, 5
Answer» C. 3, 4
4.

If Sample class has a Length property with get and set accessors then which of the following statements will work correctly?

A. 1, 3
B. 2, 4, 5
C. 4 only
D. 3, 5
Answer» C. 4 only
5.

If a class Student has an indexer, then which of the following is the correct way to declare this indexer to make the C#.NET code snippet given below work successfully?

A. class Student { int [ ] a = new int [ 5 , 5 ]; public property WriteOnly int this [ int i, int j] { set { a[i, j] = value ; } } }
B. class Student { int [ , ] a = new int [ 5 , 5 ]; public int property WriteOnly { set { a[i, j] = value ; } } }
C. class Student { int [ , ] a = new int [ 5 , 5 ]; public int this [ int i, int j] { set { a[i, j] = value ; } } }
D. class Student { int [ , ] a = new int [ 5 , 5 ]; int i, j; public int this { set { a[i, j] = value ; } } }
Answer» D. class Student { int [ , ] a = new int [ 5 , 5 ]; int i, j; public int this { set { a[i, j] = value ; } } }