Modern Programming Languages MCQs with Answers
Practice important Modern Programming Languages MCQs with answers and explanations.
Chapter: 33
Q661:
In C#, which statement is used to break out of a loop or switch statement?
A. return
B. continue
C. goto
D. break
Correct Answer:
D
Chapter: 33
Q662:
What will be the output of the following switch statement if a = 2?switch(a){ case 2: Console.WriteLine("a>1"); goto case 1; case 1: Console.WriteLine("a>0"); break; default: Console.WriteLine("a is not set"); break; }
A. a>1
B. a>0
C. a is not set
D. No output
Correct Answer:
A
Chapter: 33
Q663:
Which keyword in C# is used to indicate that a class cannot be inherited from?
A. public
B. sealed
C. abstract
D. internal
Correct Answer:
B
Chapter: 33
Q664:
In C#, the 'new' keyword is used for which of the following?
A. Static classes
B. Nested classes
C. Inheritance Methods
D. Access Modifiers
Correct Answer:
B
Chapter: 33
Q665:
Which loop type is similar to the 'do-while' loop but is executed at least once before checking the condition?
A. for
B. while
C. do-while
D. None of the above
Correct Answer:
C
Chapter: 33
Q666:
What will be the result of the following C# expression: a=5; x=a++ + --a; if evaluated right-to-left?
A. 8
B. 10
C. 5
D. 6
Correct Answer:
B
Chapter: 33
Q667:
In C#, the switch statement's expression can be of which types?
A. Integer or string
B. Boolean or integer
C. Boolean or character
D. Integer or float
Correct Answer:
A
Chapter: 33
Q668:
In C#, which class modifier is used to specify a class that cannot be instantiated directly?
A. abstract
B. sealed
C. public
D. protected
Correct Answer:
A
Chapter: 33
Q669:
What happens if a case statement in a switch expression does not contain a jump statement in C#?
A. No compilation error
B. Compilation error
C. Program crashes
D. None of the above
Correct Answer:
B
Chapter: 33
Q670:
Which control flow statement in C# is used to immediately exit from the switch, loop, or method?
A. break
B. continue
C. return
D. goto
Correct Answer:
A
Chapter: 33
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
Correct Answer:
B
Chapter: 33
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
Correct Answer:
A
Chapter: 33
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
Correct Answer:
A
Chapter: 33
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
Correct Answer:
A
Chapter: 33
Q675:
What is the default access level for a class in C#?
A. private
B. public
C. internal
D. protected
Correct Answer:
C
Chapter: 33
Q676:
Which of the following is NOT a valid C# loop control statement?
A. if
B. foreach
C. switch
D. while
Correct Answer:
B
Chapter: 33
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.
Correct Answer:
A
Chapter: 33
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
Correct Answer:
A
Chapter: 33
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
Correct Answer:
A
Chapter: 33
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
Correct Answer:
A