OOPlecture 3 - Default and Parameterized Constructor
OOPlecture 3 - Default and Parameterized Constructor
OUTPUT
Constructor
Constructor is special type of method whose name is same as class name.
OUTPUT
Type of Constructors
1) Private Constructors
2) Default Constructors
3) Parameterized Constructors
4) Copy Constructors
Default Constructor
• A constructor which does not have any parameter is default
constructor.
Default Constructor
Parameterized Constructor
A constructor through which we can pass one or more parameters is
called parameterized constructor
Syntax:
class A
{
A(int x, string y)
{
}
}
Parameterized Constructor
Class Task:
Create a Car class and its default constructor that will initialize the no of
tires and seating capacity in car.
no of tires will be 4 and seating capacity will be 5 for all car objects.
Create another constructor in Car class that will give different colors
and engine capacity to every car according to parameter passed.