Did you try to execute it? You've got a few compile errors.
Line 5: namespace is misspelled.
Line 22: Sampleclass is incorrect.
Line 28: Should be data1.
After fixing those errors, I get the following output (line #'s added):
Line 20: Default Constructor is invoked.
Line 21: 20
Line 22: Constructor SampleClass(int) in invoked
Line 23: 50
Line 24: Default Constructor is invoked.
Objects constructed = 3
|^^ wouldn't those all be objects ( the first 4 are objects of the class). |
Are constructors (functions), not instances of a class.
int getData(); is a function.
int data1; a member of a class.
a.getData() a function reference,
SampleClass a; is the only one of your 6 that instantiates a class instance.
In your program, lines 22 and 24 instantiate a temporary object that is assigned to a.