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

Answer Posted / srinu

Yes we can create a object in static block
EX:-

public class Stobject
{
static
{
Stobject st =new Stobject();
}
Stobject()
{
System .out.println("object created");
}

public static void main(String k[])
{
System .out.println("HAI");
}
}
output:-
object created
HAi

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why swings are used in java?

527


Why does JComponent have add() and remove() methods but Component does not?

561


Which package is needed for swing components?

490


What is swing control in java?

548


When we should go for codebase in applet?

621






What are the components of swing?

537


What is the difference between swing and awt?

540


Which window contains the swing controls?

532


Explain the difference between swing and jsf.

618


Why are swing components called lightweight?

544


What is java panel swing?

516


What is the function of abstractaction class?

588


Is swing still used in java?

522


Why should the implementation of any swing callback (like a listener) execute quickly?

569


What is frame in java swing?

542