- What are constructors in C# and how are they used?
- Constructors are special methods used to initialize objects of a class.
- They have the same name as the class and do not have a return type.
- Constructors can be overloaded, allowing multiple variations of object initialization.
- They are typically used to set initial values for object properties or perform necessary setup tasks.
- What is method overloading in C#?
- Method overloading allows defining multiple methods with the same name but different parameters.
- It provides flexibility and code reusability by enabling different ways to invoke a method based on the arguments.
- Overloaded methods must have different parameter lists, such as different data types or a different number of parameters.
- What is inheritance in C# and how does it work?
- Inheritance is a fundamental concept in object-oriented programming that allows creating new classes based on existing ones.
- The new class, called the derived class or subclass, inherits the characteristics (fields, properties, and methods) of the existing class, known as the base class or superclass.
- Inheritance promotes code reuse, modularity, and allows for hierarchical relationships between classes.
Comments