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


Please Help Members By Posting Answers For Below Questions

How to generate bill in java swing?

682


What is jfc swing in java?

522


Why do we use swing in java?

513


What is java swing used for?

534


What are swings awt?

546






Where is java swing used?

582


What is layout in java swing?

532


What is difference between jframe and swing?

512


Is swing an api?

543


How is parsing html used in swing?

561


What is swing framework in java?

552


What is swing api?

525


How to link two forms in java swing?

620


What are the advantages of swing over awt?

494


What is the use of jcomponent class in swing?

571