Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner classes query

 
shyamala vydyam
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I have the following classes !!



class Outer{

class InnerA extends Outer{


}

class InnerB extends InnerA{

// I have the following error while creating this inner classes


// No enclosing instance Outer available due to immediate constructor invocation
}

}


Can any one tell me why we cant extend Inner class with another inner class?

Bit confused with this !!

Thanks,
Shyamala
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


if you want to extend an Innerclass. then you must access with his constructor by enclosing class instance. i.e, some thing like this


hope this helps
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and Welcome to JavaRanch Shyamala
 
shyamala vydyam
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Seetharaman Venkatasamy ,


thats great solution but now the concept looks most contradictory where i cant create a simple object...........

new Outer().new InnerB(new Outer());

this is how we can create the object!!

where exactly this concept can be used!!??

new Outer().new InnerB();



Let me know why is this concept & its use in real time?

Thanks,
Shyamala
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add one no-arg constructor in InnerB
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inner classes are too difficult for "beginning". Thread moved to another forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic