• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

I want a example of FINAL "REGULAR" INNER CLASS. Why I want to define a final "regular" inner class?

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, below I elaborate an example of abstract inner class. But why I want to define a final inner class? How can I extend an inner class? That's because I'm confused. If I can't extend an inner class, why I have to define it final?


Example of abstract inner class:


The example below illustrate the use of an internal class and abstract (abstract inner class). Imagine that we have a class that represents a form with a button (MyForm) and that class should trigger an event by clicking on the button.

Thus, was declared an internal and abstract class (Events) whose abstract method must be implemented in the class that, in fact, will implement the behavior for the click of a button




I imagine that abstract and inner class is good for the sake of organization, but what about final and inner class ???
 
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But why I want to define a final inner class? How can I extend an inner class? That's because I'm confused. If I can't extend an inner class, why I have to define it final?


You can extend an inner class. You just need an instance of its enclosing class to call the constructor of the inner class from the sub-class. Look at this
 
pedro abs
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you !
 
pedro abs
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry but one more thing about your code:




What is the meaning of the line
new Outer().super();


I mean I'm instantiating the superclass of Outer? Just it?



 
Ankit Garg
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I mean I'm instantiating the superclass of Outer? Just it?


I can't understand what you are saying. We are instantiating the *enclosing* class of Inner class so that we can call the Inner class constructor...
 
pedro abs
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I left one link to better understand.


I have the same doubt this guy.
http://stackoverflow.com/questions/2831484/java-non-static-nested-classes-and-instance-super

Thanks again
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic