During my interview, interviewer asked me
Can we create class without name ?
Since, I was not sure, if it is really possible to create a class without name. So, I said No.
Later, I tried Googling and found, others are also looking for the answer of the same question, but I didn’t found clear answer.
I will appreciate, if anyone clearly explain about this class. I mean, what that class technically known as and how can we instantiate this class ?
Yes, it’s called an anonymous class/struct.
In C++:
xis an object of the type, and you can’t create any more, because, well, how would you, given that the class doesn’t have a name and all….You don’t. In both Java and C++ constructors and destructors hold the same name as the class (they’re not PHP –
__constructor whatever), and the missing name kind of gets in the way.