my dog learned polymorphism
The moose likes Beginning Java and the fly likes static inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static inner class" Watch "static inner class" New topic

static inner class

Ed Zeval

Joined: Jun 19, 2008
Posts: 21

I have a couple of inner classes in my code. Someone told me that I should make them static. Why would I want to do that?

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
What do your inner classes do? and what does your outer most class do?

Justin Fox

You down with OOP? Yeah you know me!
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Do you know what the difference is, technically?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Rob Spoor

Joined: Oct 27, 2005
Posts: 19844

If the inner class references some instance fields or methods of the outer class you will probably not even be able to make it static.

How To Ask Questions How To Answer Questions
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
provide some sample code if you want specific assistance

Bill Shirley - bshirley -
if (Posts < 30) JavaRanchFAQ);
I agree. Here's the link:
subject: static inner class