Skip to main content

Modern Programming Languages MCQs with Answers

Practice important Modern Programming Languages MCQs with answers and explanations.

Chapter: 34
Q681:
What does the 'static' keyword do in C#?
A. Declares a method to be a class method
B. Declares a method to be an instance method
C. Declares a method to be an abstract method
D. Declares a method to be a virtual method
Correct Answer: A
Chapter: 34
Q682:
Which method modifier in C# allows external method definitions?
A. static
B. new
C. extern
D. virtual
Correct Answer: C
Chapter: 34
Q683:
What is the key difference between hiding and overriding methods in C#?
A. Overriding always calls the base class method
B. Hiding is always done with the 'new' keyword
C. Hiding requires the method to be static
D. Overriding is less restrictive than hiding
Correct Answer: B
Chapter: 34
Q684:
In C#, how do you pass a value type by reference?
A. Use the 'ref' keyword
B. Use the 'out' keyword
C. Use the 'params' keyword
D. Use the 'static' keyword
Correct Answer: A
Chapter: 34
Q685:
Which of the following is true about the 'ref' keyword in C#?
A. The parameter must be initialized before being passed
B. The parameter can be passed uninitialized
C. The parameter is passed by value
D. The 'ref' keyword is only used for classes
Correct Answer: A
Chapter: 34
Q686:
What does the 'out' keyword in C# do?
A. Passes variables by reference without initialization
B. Passes variables by reference with initialization
C. Passes variables by value
D. It is used for method parameters only
Correct Answer: A
Chapter: 34
Q687:
What is the purpose of the 'params' keyword in C#?
A. To pass a fixed number of arguments to a method
B. To pass an arbitrary number of arguments to a method
C. To pass arguments as pointers
D. To pass arguments as reference types
Correct Answer: B
Chapter: 34
Q688:
Which of the following is NOT a valid modifier for readonly fields in C#?
A. public
B. private
C. protected
D. readonly
Correct Answer: D
Chapter: 34
Q689:
What happens if you try to assign a value to a readonly field in C# after initialization?
A. It results in a compile-time error
B. It results in a run-time error
C. The program continues without issues
D. It causes a warning but runs
Correct Answer: A
Chapter: 34
Q690:
What is the result of using the 'is' operator in C#?
A. It checks if an object is of a specific type at compile time
B. It casts an object to a specific type
C. It tests if an object is of a specific type at runtime
D. It converts an object to a string
Correct Answer: C
Chapter: 34
Q691:
How does the 'as' operator differ from casting in C#?
A. 'as' generates an exception if the cast fails
B. 'as' returns null if the cast is not valid
C. 'as' performs a deep copy of the object
D. 'as' can only be used with value types
Correct Answer: B
Chapter: 34
Q692:
What does the 'new' keyword do in C# when used with reference types?
A. It creates an object on the stack
B. It creates an object on the heap
C. It creates a new method
D. It initializes a struct
Correct Answer: B
Chapter: 34
Q693:
What is boxing in C#?
A. Converting a reference type to a value type
B. Converting a value type to a reference type
C. Converting a method to a class
D. Converting a struct to an interface
Correct Answer: B
Chapter: 34
Q694:
Which of the following is true about interfaces in C#?
A. They can have fields
B. They can have method implementations
C. They can be implemented by multiple classes
D. They cannot have constructors
Correct Answer: C
Chapter: 34
Q695:
What is the primary use of delegates in C#?
A. To define static methods
B. To pass methods as arguments
C. To handle exceptions
D. To declare event handlers
Correct Answer: B
Chapter: 34
Q696:
Which keyword is used to define a delegate in C#?
A. delegate
B. method
C. function
D. handler
Correct Answer: A
Chapter: 34
Q697:
In C#, what does the 'new' method modifier do in method hiding?
A. It allows the method to be overridden
B. It hides a method from the base class
C. It marks the method as static
D. It ensures the method cannot be called
Correct Answer: B
Chapter: 34
Q698:
Fill in the blank: In C#, a method can only have _______ return value.
A. one
B. two
C. multiple
D. no
Correct Answer: A
Chapter: 34
Q699:
What will happen if a class does not use the 'new' keyword when hiding a base class method?
A. The base class method will be called
B. The compiler will throw an error
C. The hidden method will still be called
D. The method will be ignored
Correct Answer: A
Chapter: 35
Q700:
What does PHP stand for?
A. Personal Home Page
B. PHP: Hypertext Preprocessor
C. Programming Hypertext Protocol
D. Preprocessor Hypertext Page
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Modern Programming Languages

🚀 Start Quiz Now