Why the constructor name and class name must be same?
I tried with diff name but didn't work I searched on google but I didn't get proper answer
Please help me...?
Why the constructor name and class name must be same?
I tried with diff name but didn't work I searched on google but I didn't get proper answer
Please help me...?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit MohantyPosted Oct 28, 2022, 11:17 AM
Constructor are the first thing which gets called whenever any instantiation or object of the class is created. Constructors are named same as the class name so that the compiler knows, which method to call when an object is created.
Rajanikant HawaldarPosted Oct 28, 2022, 10:58 AM
So when the class object is initializing, it has to call the constructor, if it is a different name, it wouldn't know what to call. that's is why it is law to keep the constructor name as class name