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 the use of jfc in java swing?
Explain the difference between awt and swt.
Is swing thread-safe?
What are the advantages of swing over awt?
What is layout in java swing?
What is the function of abstractaction class?
Where is java swing used?
What is jfc swing in java?
What's java swing?
What is swing gui?
What is swing api?
what are the steps required in creating an empty table drop?
How does accessibility works in swings?
How to move from one page to another in java swing?
What is swing and its features in java?