English

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
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?
Chapter 4: Constructors - Exercises [Page 116]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 4 Constructors
Exercises | Q 1. | Page 116
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×