can we create a object in static block
class A
{
static {
A a=new A();
}
}
Answer Posted / kaushal mittal
Yes we can create a object in static block.
1- if there is no main method than it will compile easily but at run time it will throw exception
//Exception in thread "main" java.lang.NoSuchMethodError:
main
2- if we put main method inside the class then it will compile and run successfully and we will get object.
| Is This Answer Correct ? | 10 Yes | 0 No |
Post New Answer View All Answers
What are the components of swing in java?
What are the two key features of swing?
What is the function of lightweight components used in swing?
Is there any heavyweight component in swings?
What is swing delegation event model in java?
What are swings?
What does javax swing do?
What are the advantage of swing over awt?
How to change button color in java swing?
What is pane in swing?
How to render an html page using only swing.
What is actionlistener in java swing?
What is import javax swing in java?
Can a class be it?s own event handler? Explain how to implement this?
Why swing is better than awt?