parameterized constructor in c++

preview_player
Показать описание
In this video you will learn parameterized constructor and how to create it.

Parameterized Constructor in c++
• In C++, A constructor which takes parameters is called as parameterized constructor.
• When we want to create object using parameterized constructor then while creating object we must pass the required arguments.
• We can define one or more than one parameterized constructor in the class with the help of function overloading.
The following example shows the parameterized constructor for Wall class.
class Wall
{ private :
int length,height,area;
public:
Wall(int l,int h)//Parameterized constructor
{ length=l; height=h; area=length*height;
}
void display()
{ cout<<"\nLength is : "<<length <<"\nHeight is : "<<height <<"\nArea is : "<<area;
}
};
int main()
{ Wall leftSide(2,5);
return 0;
}
Рекомендации по теме
Комментарии
Автор

Tq sir u really explains very well sir i hav also seen ur c language playlist nd its the best among all...

pranathisrungavarapu
Автор

agr hame parameters length and breadth user se input chaiye sir fir kese hoga?

ananyabisht