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 java swing application?
How to add calendar in java swing using eclipse?
What is double buffering ?
What is layout in java swing?
Is java swing a framework?
Which swing methods are thread-safe?
What is swing api?
What is difference between applet and swing?
What is swing gui?
How to change button color in java swing?
What is swing?
Why swings are called lightweight components?
What is the difference between swing and awt in java?
Why does JComponent have add() and remove() methods but Component does not?
What are the swing components?