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

Showing Answers 1 - 24 of 24 Answers

Anoopsada

  • 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

  Was this answer useful?  Yes

Amit Agrawal

  • 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.

  Was this answer useful?  Yes

satyarajasekhar

  • 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

  Was this answer useful?  Yes

sajimon

  • Dec 11th, 2006
 

ya,you can declare a class as static.

  Was this answer useful?  Yes

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.

  Was this answer useful?  Yes

vikas

  • Dec 15th, 2006
 

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

  Was this answer useful?  Yes

santosh

  • 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++.

  Was this answer useful?  Yes

SampathKumar G

  • 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 <identifier> 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.

Give your answer:

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

 

Related Answered Questions

 

Related Open Questions