• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner Classes

 
Lancy Mendonca
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused with the following terms used in reference to inner classes in the mock exams
- Nested top level inner class
- Member Inner class
- local class
- Local Inner class
Many Thanks
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- Nested top level inner class = top-level class defined within another top-level class. Kinda like making your own little namespace scope inside a class.
class Outer {
static class Nested {}
}
- Member Inner class = a class defined within another class class which is directly tied to an instance of the outer class. Think of it as a form of composition in which the type of the included object is defined in the holding type.
class Outer {
class Inner {}//no static keyword
}
- local class = not sure. perhaps, this should have been anonymous classes; if so, see below...
- Local Inner class = an inner class which has its instance tied to the scope of a method execution--albeit, the instance of the local class can be accessed outside the method's scope (read Java in a Nutshell for a good explanation).
class Outer {
void outerMethod1() { class Local{} }
}
- Anonymous class = a class without a name. These are very useful with event listeners. Here's an example:
Button b1 = new Button("Hey");
b1.addActionListener( new ActionListener()
{ public void actionPerformed(ActionEvent ae)
{
System.out.println("Oh my, someone hit button 1");
}
});
 
Lancy Mendonca
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a million for the reply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic