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 is swing used for?
What are swing controls?
Which window contains the swing controls?
What are the different types of layout managers used in swing?
What is a swing day?
What is import javax swing in java?
What is the difference between swing and awt?
What are the various components of swing?
What are the advantages of the event-delegation model over the event-inheritance model?
What is the function of lightweight components used in swing?
What is a component in swing?
Is swing an adjective?
What is the use of jcomponent class in swing?
What is an event in Swing?
Who created the swing?