GeekInterview.com
Series: Subject: Topic:
Question: 131 of 1115

Can we declare a class as static? If we can declare where will the execution begins?

Asked by: Interview Candidate | Asked on: Nov 14th, 2006
Showing Answers 1 - 8 of 8 Answers
Anoopsada

Answered On : Nov 16th, 2006

If it is an inner class we can declare it as static. and it act as a static object of outer class

  
Login to rate this answer.
Amit Agrawal

Answered On : Nov 16th, 2006

A outer class can not be declared static. Only inner classes can be declared static. Static inner classes imply that the object of the inner class is not dependent upon the outer class object and can exist indepenently.

  
Login to rate this answer.
satyarajasekhar

Answered On : Nov 18th, 2006

AIn order to understand the use of the static keyword in class declaration, we need to understand the class declaration itself. You can declare two kinds of classes: top-level classes and inner classes.

Top-Level Class

You declare a top-level class at the top level as a member of a package. Each top-level class corresponds to its own java file sporting the same name as the class name.

A top-level class is by definition already top-level, so there is no point in declaring it static; it is an error to do so. The compiler will detect and report this error.

Inner Classes

You define an inner class within a top-level class. Depending on how it is defined, an inner class can be one of the following four types:

Anonymous

Local

Member

Nested Top-level

For more information you can visit

http://www.javaworld.com/javaworld/javaqa/1999-08/01-qa-static2.html

  
Login to rate this answer.
sajimon

Answered On : Dec 11th, 2006

ya,you can declare a class as static.

  
Login to rate this answer.
javapitfalls

Answered On : Dec 13th, 2006

View all answers by javapitfalls

Question: Can we declare a class as static? If we can declare where will the execution begins?

I am not sure about declaring a class as static, Methods can be very well declared as static.

Execution. We cant call the members of that class directly., Its becomes mandidatory to call it by its parents class.

Ex. pow(parameter...) is static in nature.  we cant cant be called by instance of its parent class.

its should be followed by its parents class followed by a period separator i.e.,  Math.pow(2,4);

More ideas and answers are appreciated.

  
Login to rate this answer.
vikas

Answered On : Dec 15th, 2006

we can not declare top level class as static it will not compile, only inner class can be declared static

  
Login to rate this answer.
santosh

Answered On : Dec 27th, 2006

no,

because in java we will use only dyanamic .all are taken place in innerclass only not in outerclass as in c or c++.

  
Login to rate this answer.
SampathKumar G

Answered On : Jan 12th, 2007

We can declare a class as static if and only if it is inner class.Java will not allow to declare top level class as static,it will give compilation error like expected.

The execution of static keyword will start, when the class is loaded into JVM.All the static variables will instatiated first ,then static METHODs.

Yes  1 User has rated as useful.
  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.