‹ Back to the paper
Differentiate between a constructor and a method of a class.
Answer
Answer
AI1. 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.
From ISC 2017 Computer Science Paper 1, question 2(e).