• Post Reply Bookmark Topic Watch Topic
  • New Topic

Abstract Inner Class  RSS feed

 
deepak carter
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The point of your trying to do something like this is pointless to me ... but anyways ...

you can use anonymous inner classes

lalit
 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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):
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!