1-What is Constructor?

It is invoked and implemented automatically when an instance/object is initialized and for 1 time only. MUST have the same name as the className

The main use of constructors is to Change value of private fields of the class while creating an instance for the class

Constructors cannot return values explicitly (a workaround is through static const)

There are 5 types of a constructor:

1- Default Constructor → : automatically created a when there is no other constructor in the class. It initializes all numeric fields in the class to zero and all string and object fields to null. It doesn’t take any parameters

2- Parameterized Constructor → It is a constructor that takes parameters

3- Static constructor → Gets called before the object is initialized, Can’t hold parameters, There is ONLY ONE static constructor per class, Used to initialize static members or to perform a particular action that needs to be performed only once AND it is always public

4- Private constructor → Prevents the creation of an object (or inheritance) for its class, Used in a class that contains static member only and Used in Singleton Design Pattern.

5- Copy constructor → creates an object by copying variables from another object. It is a parameterized constructor that contains a parameter of the same class type.

Constructor Chaining —> Constructor chaining is the process of calling one constructor from another constructor in the same class. • This allows you to reuse initialization logic and avoid duplicating code



2-What is the difference between Abstract class and interface?