This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Abstract Inner Class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Abstract Inner Class" Watch "Abstract Inner Class" New topic
Author

Abstract Inner Class

deepak carter
Ranch Hand

Joined: Feb 19, 2011
Posts: 159
Hi All,

I created an abstract Inner class like





but i didnt got a way to how to call method show inside abstract class

so i created another inner class and made it child of abstract inner class

like this



the code is working fine but just wanted to know whetehr this is the right approach and is there ia another way

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 5893
    
    6

Right approach for what? What problem are you trying to solve with an abstract nested class? Typically nested class or interface that's meant to be extended or implemented will be static. Unless you have a really good reason to do it the way you are (which is unlikely), I would change it.
Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 369

The point of your trying to do something like this is pointless to me ... but anyways ...

you can use anonymous inner classes

lalit


http://plainoldjavaobject.blogspot.in
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
deepak carter wrote:just wanted to know whetehr this is the right approach

Almost certainly not. The appropriate situations for using an inner class are fairly limited. I can't think of a single reason to use an abstract inner class.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 4761
    
    7

deepak carter wrote:the code is working fine but just wanted to know whetehr this is the right approach and is there ia another way

I guess that depends on whether you understand why it didn't work in the first place.

Do you know what non-static nested classes are, or why you might need one? (Hint: they're quite rare.)

I'm not trying to put you down, but it seems to me that, if not, you need to do some reading in the Tutorials; otherwise, it's a bit of a waste of time.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

Are you by any chance confusing "anonymous inner class" with "abstract inner class"?

The reason abstract inner classes would make so little sense, is what would extend them? Only another inner class (as your code demonstrates)! While I suppose it could be done this way, it seems very "un-OOP" in it's in-extensibility and anti-reuse.

Anonymous inner classes, on the other hand, are pretty widely used in java, and are spoken of frequently when discussing java. That's where you implement an interface by writing out only it's required method(s):


OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Abstract Inner Class
 
Similar Threads
Inner Class
About Inner class
Inner Class Names
abstrct inner classes
overriding constructor of inner class