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 actionlistener in java swing?
What is difference between awt and swing?
Who created the swing?
Why does JComponent have add() and remove() methods but Component does not?
What are swing components?
How to align components in java swing?
What does javax swing do?
What are heavy weight components ?
What are the components of swing?
What are the benefits if Swing over AWT?
Which window contains the swing controls?
Is javafx better than swing?
What are the two key features of swing?
What is swing in java javatpoint?
Why swing components are called lightweight components?