Constructor name and class name are the same in Java. Why?
java
Solution
Because this syntax does not require any new keywords. Aside from that, there is no good reason.
To minimize the number of new keywords, I didn't use an explicit syntax like this:
class X {
constructor();
destructor();
}
Instead, I chose a declaration syntax that mirrored the use of constructors.
class X {
X();
~X();
This may have been overly clever. [The Design And Evolution Of C++, 3.11.2 Constructor Notation]
Problem
Please give me a logical answer of naming a class and constructor with same name. Why we cannot choose a different name other than class name for a constructor? ``` class Temp { Temp() { } }; ```