Question:

What is difference between static inner class & non-static inner class

by Guest57088  |  earlier

0 LIKES UnLike

what is difference between static inner class & non-static inner class

& when we perfer to use Static or non-static inner class.

 Tags:

   Report

2 ANSWERS


  1. A static class method or variable exists for the class as a whole, are shared between any and all instances of the class and are available for use even if no specific instances of the class exist. Non-static members are tied to specific instances and every instance has its own set.

    Non-static members are the norm and are used most of the time. Static members are used typically when you need to track some information about all of the instances as a whole. For example, a shopping cart app might compute shipping and handing based on total weight of the order items in addition to total order amount. Rather than going thru every order item (the instances), it may be quicker in process time to have static items for order totals and modify them as items are added or subtracted from the order.


  2. Non Static inner classes have object instances that are

    associated with the classes outer class.Static inner

    classes have no object instances.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.