enumerations c programming questions

6.

Which of the following will be the correct output for the C#.NET code snippet given below?

enum color : int
{
red = -3,
green,
blue
}
Console.Write( (int) color.red + “, “);
Console.Write( (int) color.green + “, “);
Console.Write( (int) color.blue );

A.     -3, -2, -1
B.     -3, 0, 1
C.     0, 1, 2
D.     red, green, blue
E.     color.red, color.green, color.blue
Answer & Explanation

Answer: Option A

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
7.

An enum that is declared inside a class, struct, namespace or interface is treated as public.
A.     True    B.     False
Answer & Explanation

Answer: Option A

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
8.

Which of the following statements is correct about the C#.NET code snippet given below?

enum per
{
married,
unmarried,
divorced,
spinster
}
per.married = 10;
Console.WriteLine(per.unmarried);

A.     The program will output a value 11.
B.     The program will output a value 1.
C.     The program will output a value 2.
D.     The program will report an error since an enum element cannot be assigned a value outside the enum declaration.
E.     The enum elements must be declared private.
Answer & Explanation

Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
9.

Which of the following is the correct output for the C#.NET code snippet given below?

enum color: int
{
red,
green,
blue = 5,
cyan,
magenta = 10,
yellow
}
Console.Write( (int) color.green + “, ” );
Console.Write( (int) color.yellow );

A.     2, 11
B.     1, 11
C.     2, 6
D.     1, 5
E.     None of the above
Answer & Explanation

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
10.

An enum can be declared inside a class, struct, namespace or interface.
A.     True    B.     False
Answer & Explanation

Answer: Option A

Explanation:

No answer description available for this question.

Leave a Reply0

Your email address will not be published.