• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inner and Abstract class  RSS feed

 
Anupama D S
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all


Is it legal(not in terms of syntax) to define inner class inside abstract class does it comes under any design pattern?
 
Campbell Ritchie
Marshal
Posts: 56581
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would appear to have missed the JavaRanch naming policy when you signed up. Please check it and amend your displayed name in "my profile."

I think it is legal to declare such an inner class, yes, but if you give it private access it can only be used inside the abstract class. I don't know what pattern name you would put to that.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anupama D S:
Is it legal(not in terms of syntax) to define inner class inside abstract class does it comes under any design pattern?


If "not in terms of syntax", then what?

Anyway, the answer is yes, it is legal to have an inner class inside an abstract class.

Further, as well as being legal, it is also sometimes a reasonable thing to do. After all, an abstract class contains (partial) implementation code, and that implementation will sometimes be best achieved with the help of an inner class.
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As stated, it would be perfectly reasonable to implement an abstract class, and have one or more inner classes that "complete" the implementation within the same file.

Designs are just names that people have put to common design problem/solutions. It's just likely not that common.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!