C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 47)
47.
What will happen if a class is not having any name?
It cannot have a destructor.
It cannot have a constructor.
It is not allowed.
Both A and B.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
25 comments Page 2 of 3.

Jatin said:   10 years ago
@Rahul.

I'm not getting any output as per your code.

Chintan said:   10 years ago
If you create class but not having any name, gives compilation error. So I think answer C is right.

Tejas said:   1 decade ago
But my compiler reports an error.

Naveen pateriya vidisha said:   1 decade ago
Nice discussion its possible blindly to create a name less class.

Rahul said:   1 decade ago
#include<iostream.h>
class { public : int x; }a; //a is the object of this class

int main(){

a.x=10;
cout<<"a="<<a.x;
return 0;

}

Execute the above code one can get to know about class without name.

Rinku said:   1 decade ago
How can possible without class name constructor and destructor?

Rhuda said:   1 decade ago
Its possible in C++ but is this true for java?

Seema said:   1 decade ago
We can create objects of nameless class but at the time of creation of the class.

For example this perfect.

class { public : intx }a; //a is the object of this class

main(){

a.x=10;
cout<<"a="<<a.x;

}

Kushal tewatia said:   1 decade ago
Can somebody give the example of a class having without name.

Sonu said:   1 decade ago
As name of class is d essential requirement to create constructor and destructor. So it can not be created. And also we can not create object of an Abstract class.

So Answer is option :D.


Post your comments here:

Your comments will be displayed after verification.