Welcome to the C# Object-Oriented Programming (OOP) Quiz! This quiz is designed to test your understanding of key concepts in object-oriented programming, specifically in C#. You’ll encounter questions on topics such as objects, classes, constructors, properties, access modifiers, static members, and more. These concepts are fundamental to writing clean, reusable, and maintainable code in C#. Take your time, think through each question carefully, and good luck on your journey to mastering object-oriented programming!
1.
What is a static member in C#?
2.
What is a primary constructor in C#?
3.
What does the following constructor do?
public DemoClass(string name, int age)
{
this.name = name;
this.age = age;
}
4.
How do you define a finalizer in C#?
5.
What is the role of a finalizer in C#?
6.
What is the this keyword used for in C#?
7.
What is the purpose of the constructor in the following C# code?
public BankAccount(string accountName, int accountNumber)
{
_accountName = accountName;
_accountNumber = accountNumber;
}
8.
Which keyword is used to declare a method as a static method in C#?
9.
What is the purpose of a method in a C# class?
10.
What is the purpose of the readonly keyword in C#?
11.
How can a static method be accessed in C#?
12.
What is an object in object-oriented programming?
13.
What does the dot notation in C# allow you to do?
14.
How do you create an instance of a class in C#?
15.
What is the primary purpose of a constructor in a C# class?
16.
What is the role of the get accessor in a property?
17.
What is the difference between a field and a property in a C# class?
18.
Which of the following is a public field in C#?
19.
How does a property in C# provide access to a private field?
20.
What is data encapsulation in object-oriented programming?
21.
Which access modifier allows unrestricted access to a class or its members?
22.
What is the relationship between a class and an object?