can we create a object in static block
class A
{
static {
A a=new A();
}
}
Answer Posted / 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 |
Post New Answer View All Answers
What is jfc swing in java?
Which swing methods are thread-safe?
What is the difference between applications and applets?
What are the components of java swing?
Can a class be it?s own event handler? Explain how to implement this?
am searching for the job based on java, swing, currently working small company. they are not giving any salary slip, offer letter. so if i try outside for MNC's they start with previous company details. what should i do..? please help me to get job and make my career.
What is javax swing joptionpane?
Why swings are used in java?
What is double buffering ?
What is the use of jfc in java swing?
Which method is used for setting security in applets?
How to reload a jframe in java swing?
What are the benefits of swing over awt?
Is java swing deprecated?
What is java swing package?