• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inner Class in Java

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the basic utility of Inner Class in Java
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the JavaRanch campfire story, Getting in touch with your inner class.
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a loaded question, especially since there are multiple types of inner classes. The more useful question is when do you use inner classes, which is primarily in swing apps to implement quick threads. I'll let someone else take the rest...
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One interesting consideration is that inner classes can inherit independently from their enclosing class. So considering the special "link" an inner class has to its enclosing class, this might be considered a form of multiple inheritance...
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
U can also use inner class to maintain Data Integrity in DataBase.
For eg.
Consider u have a Customer Info as a parent Table and their Address as a inner table or a table with foreign key.
Make Customer as a Parent Class and Address as a inner class.
Now u have to fill in Customer table, then only enter address table. Kinda access to Address(<B>Child class</B> info is got only if the Customer(<B>Parent Class</B> is accessed first.

This is similar to what marc has given in his link. but the use is different.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is asking basic information about inner classes really an advanced question?
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeff Albrechtsen:
Is asking basic information about inner classes really an advanced question?



No.
I find this forum full of questions that are posed by people who think it is advanced. Another case of "how things appear versus how things are" where the former is preferred by a majority. The Intermediate forum has more interesting topics, at least to me. Give it a shot.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sriram:
U can also use inner class to maintain Data Integrity in DataBase.
For eg.
Consider u have a Customer Info as a parent Table and their Address as a inner table or a table with foreign key.
Make Customer as a Parent Class and Address as a inner class.
Now u have to fill in Customer table, then only enter address table. Kinda access to Address(<B>Child class</B> info is got only if the Customer(<B>Parent Class</B> is accessed first.



Don't do this. Relationships between entities should be modelled as containment (or references) relationship. Inner classes are totally wrong for this.

For example, a customer probably has exactly one (or a fixed/maximum number of) addresses. That cannot be modelled using inner classes.
 
I found a beautiful pie. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic