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 inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inner class " Watch "inner class " New topic
Author

inner class

Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
why cant an inner class have static members?


scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
is this because inner class cant live without an instance of the outerclass...so if the inner class could have static memebers then we would be able to invoke them by just using the class name of the inner class which is what we dont want..what we want is that inner class be associated only with an instcne of the otuer class??
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
and thus similarly we cant create an instance of an inner class from the static method of the outer class...right?
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

Raju Champaklal wrote:and thus similarly we cant create an instance of an inner class from the static method of the outer class...right?


We can create an instance of an inner class from static method of the outer class, if we declare the inner class as static..


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

Raju Champaklal wrote:and thus similarly we cant create an instance of an inner class from the static method of the outer class...right?


We could create an instance of the outer class and then create instance of the inner class.

This would work.


"A problem well stated is a problem half solved.” - Charles F. Kettering
SCJP 6, OCPJWCD
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 791

@ Raju
See 8.1.3 Inner Classes and Enclosing Instances


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
 
GeeCON Prague 2014
 
subject: inner class