Q) Class and Object, Its relationship and Definition:

A) A class acts as a blue print that defines the properties, states and behaviors that are common to a number of objects.(In other words A Class describes all the attributes of the object, as well as the methods that implement the behavior of the member object. In simple, class is a template of an object.)

An object is an instance of the class.
For eg: Vehicle is a class and Car is an object.

A class can have multiple objects

Eg: Van, Trunk and Auto are the objects of vehicle class


Q) What is ‘New’ operator?

A) The new operator is used to create an object of a class. When an object of a class is instantiated, the system allocates memory for every data member that is present in class.


Q) What is Constructor?

A) Constructor is a special method of a class which is automatically invoked when the instance of a class is created.

It is created with same name as the class and initializes all class members, whenever you access the class.

We can have multiple constructors for the same class


Q) What are the main features of constructor?

A) Constructor do not have any return type(not even void).
Constructors can be overloaded.
It is not mandatory to declare a constructor, it is invoked by .Net framework.


Q) What is the Constructor Chaining in C#?

A) In Constructor Chaining every child class constructor is mapped to parent class Constructor implicitly by base keyword so when you create an instance of child class, it’ll call parent’s class Constructor


Q) What is Static constructor in C#?

A)If the constructor is declared as static then it will be invoked only once for all number of instances of a class. Static constructor will initialize the static fields of a class. Below is the example:

class TestClass
{
 public string prop1, prop2;
 public TestClass(string x, string y)
 {
 prop1 = x;
 prop2 = y;
 }

Static TestClass()
 {
 Console.WriteLine(“Static Constr Test”);
 }
 public TestClass(TestClass myobj) // Copy Constructor
 {
 prop1 = myobj.prop1;
 prop2 = myobj.prop2;
 }
}

Q) What is Copy constructor in C#?

A)If the constructor contains the same class in the constructor parameter then it is called as copy constructor.

class TestClass
{
 public string prop1, prop2;
 public TestClass(string x, string y)
 {
 prop1 = x;
 prop2 = y;
 }
 
 public TestClass(TestClass myobj) // Copy Constructor
 {
 prop1 = myobj.prop1;
 prop2 = myobj.prop2;
 }
}

Q) What is the real need of Abstract class?

A) we define abstract class when we define a template that needs to be followed by all the derived classes.

All the abstract methods in an abstract class need to be overridden compulsorily.


Q) What is the difference between Abstract class and Interface?

A)

AbstractInterface
Abstract class cannot be instantiated but we can inherit itInterface cannot be Inherited but can be instantiated
Abstract contains both declarations and definitionsInterface contains only declarations
A class which contains abstract method is abstract classClass which contains only abstract methods is interface class
In abstract class we have a chance of declaring any access specifiersBy default public is access specifier for interface. we don’t have chance to declare other specifiers.


Q) What are properties of Abstract class?

A) It cannot be private(By default it is public)
It cannot be static
It cannot be sealed(It has to be inherited)
Abstract class cannot be used with virtual keyword. By default they are virtual and need to be overridden child classes.


Q) Basic features of OOPS:

A) The new operator is used to create an object of a class. When an object of a class is instantiated, the system allocates memory for every data member that is present in class.

The following are are four basic features of OOPS:

Abstraction: Refers to the process of exposing only the relevant and essential data to the users without showing unnecessary information.

Polymorphism: Allows you to use an entity in multiple forms.

Encapsulation: Prevents the data from unwanted access by binding of code and data in single unit called object.

Inheritance: Promotes the re-usability of code and eliminates the use of redundant code. It is the property through which a child class obtains all the features defined in its parent class.


Q) What are the different ways a method can be overloaded?

A)Methods can be overloaded using different data types for parameter, different order of parameters, and different number of parameters.


Q) What is difference between late binding and early binding in C#?

A. Polymorphism is the feature of object oriented programming that allows a language to use same name in different forms. It can be achieved by 2 different types:

1.Compile time (Also known as early binding or Overloading)

2.Run time(Also known as Late binding or Overriding)


Q) What is IEnumerable<> in C#?

A)IEnumerable is the parent interface for all non-generic collections in System.Collections namespace like ArrayList, HastTable etc.

IEnumerable<T> is a parent interface of all generic collections like List