Modern Programming Languages MCQs with Answers
Practice important Modern Programming Languages MCQs with answers and explanations.
Multiple Choice Questions
Q671: What does the following C# code do? switch(option){ case "label": goto case "jump"; case "quit": return; case "spin": for(;;){ } case "jump": case "unwind": throw new Exception(); default: break; }
- A: Returns an error message
- B: Throws an exception
- C: Infinite loop
- D: Exits the program
View Answer
B
Q672: Which loop in C# has a condition checked before each iteration and may not execute if the condition is false initially?
- A: while
- B: do-while
- C: for
- D: foreach
View Answer
A
Q673: The 'goto' statement in a switch statement in C# is used to jump to which of the following?
- A: Any case or default block
- B: Another method
- C: Another loop statement
- D: Another class
View Answer
A
Q674: Which of the following class modifiers makes a class available to types within the same assembly?
- A: internal
- B: protected
- C: public
- D: abstract
View Answer
A
Q675: What is the default access level for a class in C#?
- A: private
- B: public
- C: internal
- D: protected
View Answer
C
Q676: Which of the following is NOT a valid C# loop control statement?
- A: if
- B: foreach
- C: switch
- D: while
View Answer
B
Q677: What does the 'abstract' keyword do when applied to a class in C#?
- A: It prevents the class from being instantiated.
- B: It prevents the class from being inherited.
- C: It makes the class accessible from outside.
- D: It makes the class static.
View Answer
A
Q678: What will happen if a 'foreach' loop is used to iterate through a non-IEnumerable object in C#?
- A: Compilation error
- B: Runtime error
- C: No output
- D: Infinite loop
View Answer
A
Q679: What will the output be when running the following code? int[] a = new int[]{1,2,3}; foreach (int b in a) Console.WriteLine(b);
- A: 1 2 3
- B: 1 2
- C: 3
- D: No output
View Answer
A
Q680: In C#, which type of loop should be used when you want the condition to be evaluated before each iteration?
- A: while
- B: for
- C: do-while
- D: None of the above
View Answer
A