Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Answers were Sorted based on User's Feedback



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

Answer / kaushal mittal

Yes we can create a object in static block.
1- if there is no main method than it will compile easily but at run time it will throw exception
//Exception in thread "main" java.lang.NoSuchMethodError:
main
2- if we put main method inside the class then it will compile and run successfully and we will get object.

Is This Answer Correct ?    10 Yes 0 No

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

Answer / anjani kumar jha

Yes We can do..........................there is no problem

static
{
FileSize fz=new FileSize();
System.out.println(fz);
}

Is This Answer Correct ?    9 Yes 0 No

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

Answer / 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

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

Answer / rabin pati

Yes we can create

Is This Answer Correct ?    5 Yes 0 No

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

Answer / chellammal

Yes, we can create a object in static block

Is This Answer Correct ?    5 Yes 1 No

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

Answer / naresh tuhania

Yes we can do this . Because we can create an object at
runtime and static block is also execute when a class is
loaded by the class loader at runtime

Is This Answer Correct ?    3 Yes 0 No

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

Answer / 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

More Swing Interview Questions

What is the use of swing in java?

0 Answers  


What is the class in swing to change the appearance of the frame in runtime?

0 Answers  


Does Swing contains any heavy weight component?

5 Answers  


Why would you use swingutilities.invokeandwait or swingutilities.invokelater?

0 Answers  


What is double buffering ?

0 Answers  


How to create image slideshow in java swing?

0 Answers  


How to move from one page to another in java swing?

0 Answers  


Which layout does swing use by default?

0 Answers  


What do you mean by java swing?

0 Answers  


How to print in java swing application?

0 Answers  


What are the swing components in java?

0 Answers  


What's java swing?

0 Answers  


Categories