简体   繁体   中英

Inheritance and inner classes in java?

I am confused on why should or when shall I write an inner class in java.

Say I encountered a method like execute in some ExecutorService class .parameter of execute is runnable type.Why shall I write inner class for parameter of this method.

Also ,How inheritance work on inner classes like My class has some inner class and how inheritance (ie overriding overloading works there). Pointers\\tutorials are welcome. Thanks in advance Gaurav

When we use inner classes, we reference their objects with OuterClassName.InnerClassName .

This is necessary because objects of any non-static inner class can only be created in association with an object of the outer class, outside of any non-static method within the outer class.

Take a look at Using inner and nested Java classes for more information and exmples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM