Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 2(e)

2 marks

Computer ScienceISC 2017 Computer Science Paper 1DifferentiateObjects

Differentiate between the following.

Differentiate between a constructor and a method of a class.

Answer

Answer

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.