aspose file tools*
The moose likes Beginning Java and the fly likes Regarding Static Declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regarding Static Declaration" Watch "Regarding Static Declaration" New topic
Author

Regarding Static Declaration

surya.raaj prakash
Ranch Hand

Joined: Oct 30, 2009
Posts: 76
Hi Friends,

I'm new to Java Technology,please clarify my doubts.Can we declare the class and constructor as a static?
Anjali Raman
Ranch Hand

Joined: Nov 28, 2007
Posts: 57
Helo,
Only a inner class can be defined as static, the top level class cannot be static.(Please correct me if I am wrong)
Also the constructor cannot be static, the compiler will complain in both these cases.

Cheers,
Anjali
surya.raaj prakash
Ranch Hand

Joined: Oct 30, 2009
Posts: 76
Hi Anjali,

Thanks For Your Reply,

Can we call the static method from constructor?
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

surya.raaj prakash wrote:Can we call the static method from constructor?

Have you try it out. What was the result?


http://muhammadkhojaye.blogspot.com/
Anjali Raman
Ranch Hand

Joined: Nov 28, 2007
Posts: 57
Hi there,
yes you can call static methods from constructor. I have written a example here and hope it should make you understand things better.



surya.raaj prakash
Ranch Hand

Joined: Oct 30, 2009
Posts: 76
Hi Anjali,
Thank You.

But Why compiler not allowing to declare constructor as a static?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

What's the use of adding it? It's already implicitly static since you cannot call it on an existing instance. Instead of allowing it, adding to more confusion, Sun decided that it's simply not possible. They could also have made it required but Sun know that programmer's are inherently lazy, and leaving out the static keyword for each constructor will save a lot of typing.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
surya.raaj prakash
Ranch Hand

Joined: Oct 30, 2009
Posts: 76
Hi Rob,
Thank You Very Much.

But one more doubt,please clarify to me,

But Why The class itself isn't "static",and there no such thing as a static class.But it is Static nested class.
surya.raaj prakash
Ranch Hand

Joined: Oct 30, 2009
Posts: 76
Hi Rob,
Thank You Very Much.

But one more doubt,please clarify to me,

But Why The class itself isn't "static",and there no such thing as a static class and compiler not allowed.But it is Static nested class.
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
What do you think a static top-level class would mean?

John.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding Static Declaration