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

What is swing package in java?

524


What is an event in Swing?

608


Why is model-view-controller architecture used in swing?

547


What is the difference between invokeAndWait() and invokeLater()?

595


What is the difference between swing and awt?

540






What is the use of java swing?

530


What is awt and swing in java?

506


What is swing and awt in java?

519


How is parsing html used in swing?

565


What are the benefits if Swing over AWT?

598


How to render an html page using only swing.

595


What are the different components that are used to show a container?

545


What is a swing day?

534


What do you mean by java swing?

516


Which layout does swing use by default?

498