Questions and CORRECT Answers
1. What are the key differences between functional programming and object-oriented
programming (OOP)? - CORRECT ANSWER - Functional programming focuses on
immutable data and pure functions without side effects, emphasizing what to solve. OOP
organizes code around objects and classes, emphasizing how to solve using encapsulation,
inheritance, and polymorphism.
2. Why is OOP widely used in modern software development? - CORRECT ANSWER -
OOP helps manage complex software by promoting code reusability, modularity, encapsulation,
and maintenance. It maps well to real-world concepts, making code more intuitive and scalable.
3. What are the four pillars of OOP? - CORRECT ANSWER - Encapsulation - Hiding
internal details and exposing only necessary parts.
Abstraction - Simplifying complex systems by modeling classes appropriate to the problem.
Inheritance - Creating new classes from existing ones to promote reuse.
Polymorphism - Allowing objects to be treated as instances of their parent class.
4. What are the key features of C# as an OOP language? - CORRECT ANSWER - Strong
type system
Support for classes, inheritance, interfaces
Properties, methods, constructors
Access modifiers (e.g., public, private)
, Garbage collection
Integration with the .NET framework
5. Explain the role of the .NET platform in C# development. - CORRECT ANSWER -
.NET provides a runtime environment, class libraries, and language interoperability for C#. It
simplifies application development by handling memory management, security, exception
handling, and more.
6. What is the Common Language Runtime (CLR), and why is it important? - CORRECT
ANSWER - CLR is the execution engine for .NET applications. It handles JIT
compilation, memory management, security, and garbage collection, allowing C# code to run
smoothly and safely across different environments.
7. What is Just-In-Time (JIT) compilation, and how does it work in .NET? - CORRECT
ANSWER - JIT compiles Intermediate Language (IL) code into native machine code at
runtime. This allows .NET programs to be platform-independent initially and optimized during
execution.
8. How does C# differ from dynamically typed languages like Python? - CORRECT
ANSWER - C# is statically typed, meaning types are checked at compile time, leading to
fewer runtime errors. Python is dynamically typed, with more flexibility but potentially more
runtime issues. C# also has stronger tooling support like IntelliSense and compile-time checking.
9. How do you create a simple class in C#? Provide an example. - CORRECT ANSWER -
public class Person { public string Name public int Age public void Greet() {
Console.WriteLine($"Hello, my name is {Name} and I am {Age} years old.")} }
10. What is the difference between a property and a field in a C# class? - CORRECT
ANSWER - A field is a variable declared directly in a class.
A property provides controlled access to fields and can include getters and setters.
Example: