Home Subjects C# Programming

C# Programming

C# and .NET for campus placement

154 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 51–60 of 154
Topics in C# Programming
Q.51 Medium OOP in C#
What is the output of the following C# code?
public class Animal { public virtual void Sound() { Console.WriteLine("Some sound"); } }
public class Dog : Animal { public override void Sound() { Console.WriteLine("Bark"); } }
Animal animal = new Dog();
animal.Sound();
A Some sound
B Bark
C Compilation error
D Runtime error
Correct Answer:  B. Bark
EXPLANATION

Due to polymorphism, the overridden method in Dog class is called at runtime, printing 'Bark' even though the reference type is Animal.

Test
Q.52 Medium OOP in C#
A restaurant ordering system needs to ensure each order has a unique ID generated automatically. Which design pattern and feature should be used?
A Static variable in Order class
B Public variable in Order class
C Protected variable with inheritance
D Interface implementation
Correct Answer:  A. Static variable in Order class
EXPLANATION

Static variables are shared across all instances and can be used to generate unique IDs automatically without modifying external data.

Test
Q.53 Medium OOP in C#
Which of the following statements about virtual methods in C# is TRUE?
A Virtual methods cannot be overridden in derived classes
B Virtual methods allow derived classes to override the base implementation
C Virtual methods are automatically static
D Virtual methods must be abstract
Correct Answer:  B. Virtual methods allow derived classes to override the base implementation
EXPLANATION

Virtual methods are designed to be overridden by derived classes, enabling polymorphic behavior and runtime method resolution.

Test
Q.54 Medium OOP in C#
A vehicle management system requires different vehicle types (Car, Bike, Truck) to calculate toll fees differently. Which feature should be used?
A Method Overloading
B Method Overriding
C Polymorphism through inheritance
D Encapsulation
Correct Answer:  C. Polymorphism through inheritance
EXPLANATION

Polymorphism through inheritance allows each vehicle type to override the toll calculation method with its own implementation, enabling different behavior for each type.

Test
Q.55 Medium OOP in C#
What is the difference between 'sealed' and 'abstract' keywords in C#?
A sealed prevents inheritance; abstract requires inheritance
B abstract prevents instantiation; sealed allows instantiation
C Both prevent instantiation
D sealed creates static members; abstract creates virtual members
Correct Answer:  A. sealed prevents inheritance; abstract requires inheritance
EXPLANATION

sealed prevents a class from being inherited, while abstract requires derived classes to implement its abstract members. They serve opposite purposes.

Test
Q.56 Medium OOP in C#
In a library management system, multiple types of items (Book, Magazine, DVD) share common properties like ID and Title. Which OOP principle should be applied here?
A Polymorphism
B Inheritance
C Encapsulation
D Abstraction
Correct Answer:  B. Inheritance
EXPLANATION

Inheritance allows creating a base class (LibraryItem) with common properties, and derived classes can inherit these properties, reducing code duplication.

Test
Q.57 Medium ASP.NET Basics
What is Entity Framework in ASP.NET context?
A An ORM (Object-Relational Mapping) tool for database operations
B A JavaScript framework
C A security framework
D A caching mechanism
Correct Answer:  A. An ORM (Object-Relational Mapping) tool for database operations
EXPLANATION

Entity Framework is Microsoft's ORM that allows developers to work with databases using .NET objects instead of raw SQL.

Test
Q.58 Medium ASP.NET Basics
Which of the following methods is used to pass data from Controller to View in ASP.NET MVC?
A ViewBag and ViewData
B Session State only
C Query strings only
D Cookies only
Correct Answer:  A. ViewBag and ViewData
EXPLANATION

ViewBag (dynamic) and ViewData (dictionary) are common ways to pass data from Controller to View in ASP.NET MVC.

Test
Q.59 Medium ASP.NET Basics
What is the purpose of the [ValidateAntiForgeryToken] attribute in ASP.NET MVC?
A To prevent Cross-Site Request Forgery attacks
B To validate user input format
C To encrypt form data
D To authenticate user sessions
Correct Answer:  A. To prevent Cross-Site Request Forgery attacks
EXPLANATION

[ValidateAntiForgeryToken] verifies that form submissions come from your application, preventing CSRF attacks.

Test
Q.60 Medium ASP.NET Basics
In an ASP.NET Core application, where is Dependency Injection configured?
A In the Startup.cs ConfigureServices method
B In the web.config file
C In the appsettings.json file only
D In the Global.asax file
Correct Answer:  A. In the Startup.cs ConfigureServices method
EXPLANATION

Dependency Injection is configured in the ConfigureServices method of Startup.cs (or Program.cs in newer versions).

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips