can we create a object in static block
class A
{
static {
A a=new A();
}
}

Answer Posted / karthik

We can create object because static block is a executable
block and we don't want any Instance to call. It will be
called before executing or calling the main thread
But here we will get object and exception
//Exception in thread "main" java.lang.NoSuchMethodError:
main

Is This Answer Correct ?    6 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is swing thread-safe?

751


What is the difference between a scrollbar and a jscrollpane ?

1035


How to perform action on button in java swing?

694


What is jpanel swing?

838


How is multi-threading gets implemented using swing?

722


Why are swing components called lightweight components?

681


What are the containers available in swing?

729


What is import javax swing jframe?

756


How do you swing an applet?

810


What is jfc swing in java?

718


How to reload a jframe in java swing?

766


What is the difference between swing and awt?

715


What is the process of setting the layout manager?

766


What class is at the top of the AWT event hierarchy?

846


Why swing is better than awt?

732