File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static question

 
Swagato Bhatta
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


When the above code is run, I get the following


What is going on here? Why is modifier static now allowed at line 1?
 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
most outer class cannot be declare as static as per jls.
 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 400
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes true, the most outer class.
 
Swagato Bhatta
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 400
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 400
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
welcome
 
Abhishek Bose
Greenhorn
Posts: 24
Android Chrome Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 295
Eclipse IDE Firefox Browser Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic