PRASHNIKAप्रश्निका
‹ Back to the paper

Differentiate between a constructor and a method of a class.

Computer Science20172 marksShort answer

Answer

Answer

AI
1. A constructor has the same name as the class and no return type (not even void); a method has any valid name and must have a return type (or void). 2. A constructor is invoked automatically when an object is created with new and is used to initialise the data members; a method is invoked explicitly by the object (object.method()) and performs an operation on the data.
Objects

From ISC 2017 Computer Science Paper 1, question 2(e).