Advertisements
Advertisements
प्रश्न
Constructors can be applied to all the programs that contain member data. Upgrade the programs done till now, so as to include constructors in them.
कोड लेखन
Advertisements
उत्तर
Constructors can be added to all classes that contain member data. A constructor initializes the data members automatically when an object is created. Therefore, all the programs written earlier should be upgraded by adding suitable constructors (default or parameterized) to initialize their member data before calling other member methods.
class Student
{
int rollNo;
String name;
Student()
{
rollNo = 0;
name = "";
}
}shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
