Advertisements
Advertisements
Question
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.
Code Writing
Advertisements
Solution
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
Is there an error in this question or solution?
