• 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

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if we entend a inner class without outer class it shows an error.
But if we implements an inner interface without extending outer class didn't show an error.

if we extend outer class does the inner class automatically extend or not
if not then how can we extend the inner class.

class inter
{
interface a
{
void m1();
}

}

class interchild implements inter.a
{
public void m1()
{

}
public static void main(String[] ar)
{
inter i=new inter();
i.m1();
}
}


this will not show any error if we change the inner interface with inner class and if we put "extends inter.<inner class name> " it shows an error
why?
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ashok,
The member interfaces are implicitly static.so an enclosing class instance is not required.when u extend a inner class,it requires enclosing class instance.
Here is a code to extend inner class....

The output is:
in outer class constructor
inner class constructor
another class constructor
Hope this helps....
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SECOND WARNING

"ashokkumar"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic