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

What are controls and what are different types of controls in awt?

754


What are swings awt?

704


What is swing used for?

659


What is the role of java swing?

695


Why swing is used in java?

730


What is swing gui?

672


What is the base class for all swing components?

786


Is swing thread-safe?

752


What are the advantages of the event-delegation model over the event-inheritance model?

856


Is java swing a framework?

751


What is jpanel swing?

841


Is java swing still used?

713


What is difference between jframe and swing?

705


What is the difference between swing and awt?

715


What are heavy weight components ?

799