Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inner class

 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why cant an inner class have static members?
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Nidhi Sar
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Java Linux
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic