File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static question" Watch "Static question" New topic
Author

Static question

Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72


When the above code is run, I get the following


What is going on here? Why is modifier static now allowed at line 1?


Working on my SCWCD so I can be a J2EE consultant earning millions of dollars and showing everyone I can
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

most outer class cannot be declare as static as per jls.


SCJP6 96% | SCWCD5 81% | SCDJWS5 79%
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

I mean a class it self cannot declare as static but you can have a static inner class object in a class.
Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72
Minhaj kaimkhani wrote:I mean a class it self cannot declare as static but you can have a static inner class object in a class.


So I think what you mean is that I can never have outter static class. Is that what you mean?
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

yes true, the most outer class.
Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72
Minhaj kaimkhani wrote:yes true, the most outer class.


:-) What do you mean by the word "most"? Are there exceptionsss to the rule?
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

well as i said before a class can have another class(i.e. Inner class) that can be declared as static;
example:


in the above case Clazz is the most outer class.
Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72
Minhaj kaimkhani wrote:well as i said before a class can have another class(i.e. Inner class) that can be declared as static;
example:


in the above case Clazz is the most outer class.


Thank you
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

welcome
Abhishek Bose
Greenhorn

Joined: Dec 14, 2009
Posts: 24

Swagato Bhatta wrote:
Minhaj kaimkhani wrote:well as i said before a class can have another class(i.e. Inner class) that can be declared as static;
example:


in the above case Clazz is the most outer class.


Thank you



What if we declare a static class implementing a comparator<>?
Javin Paul
Ranch Hand

Joined: Oct 15, 2010
Posts: 281

Abhishek Bose wrote:
Swagato Bhatta wrote:
Minhaj kaimkhani wrote:well as i said before a class can have another class(i.e. Inner class) that can be declared as static;
example:


in the above case Clazz is the most outer class.


Thank you



What if we declare a static class implementing a comparator<>?


do it as static nested Class. it make sense and its standard way of doing it.


http://javarevisited.blogspot.com - java classpath - Java67 - java hashmap - java logging tips java interview questions Java Enum Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static question