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

Which package is needed for swing components?

487


What are the swing components in java?

503


What is jpanel swing?

557


What is swing framework in java?

552


What is java swing used for?

534






What is swing package in java?

520


Explain how to render an html page using only swing.

1024


What are the two key features of swing?

528


What are differences between swing and awt?

526


What's java swing?

568


Which method of the Component class is used to set the position and size of a component?

564


Write a program to paint the off-screen buffer in swings

559


What is java swing components?

532


Is java swing still used?

533


Which swing methods are thread-safe?

642