Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inner class extending

In java, say I have the following class:

public class A{
  protected class B{
  }
}

can I extend the inner class by doing the following?

public class C extends A{
  protected class D extends B{
  }
}

What I want to do is that I have the class C above and I need to change something in A's inner class so I was thinking that I need to extend the inner class to do so but I wasn't sure how exactly to do that.

like image 324
user1082160 Avatar asked Feb 26 '12 23:02

user1082160


People also ask

What class must an inner class extend?

Any class. I'd say C is correct, because the group Any class or interface includes Object. The way I understand option B is "An inner class must extend the Object class.", and that would force us to extend all inner classes from Object.

Can nested classes be extended in Java?

It can be accessed without instantiating the outer class, using other static members. Just like static members, a static nested class does not have access to the instance variables and methods of the outer class. You can extend static inner class with another inner class.

Can local inner class extends another class?

Local inner classes can extend an abstract class or implement an interface.


1 Answers

According to this page, you have the right way figured out to extend inner classes. A few tips about it can be found here, in the middle of the article (search for "extend").

like image 81
malexmave Avatar answered Oct 09 '22 13:10

malexmave