Quantcast
Viewing latest article 4
Browse Latest Browse All 15

Answer by Gaurav Tiwari for Static nested class in Java, why?

Adavantage of inner class--

  1. one time use
  2. supports and improves encapsulation
  3. readibility
  4. private field access

Without existing of outer class inner class will not exist.

class car{    class wheel{    }}

There are four types of inner class.

  1. normal inner class
  2. Method Local Inner class
  3. Anonymous inner class
  4. static inner class

point ---

  1. from static inner class ,we can only access static member of outer class.
  2. Inside inner class we cananot declare static member .
  3. inorder to invoke normal inner class in static area of outer class.

    Outer 0=new Outer();Outer.Inner i= O.new Inner();

  4. inorder to invoke normal inner class in instance area of outer class.

    Inner i=new Inner();

  5. inorder to invoke normal inner class in outside of outer class.

    Outer 0=new Outer();Outer.Inner i= O.new Inner();

  6. inside Inner class This pointer to inner class.

    this.member-current inner classouterclassname.this--outer class

  7. for inner class applicable modifier is -- public,default,

    final,abstract,strictfp,+private,protected,static

  8. outer$inner is the name of inner class name.

  9. inner class inside instance method then we can acess static and instance field of outer class.

10.inner class inside static method then we can access only static field of

outer class.

class outer{    int x=10;    static int y-20;    public void m1() {        int i=30;        final j=40;        class inner{            public void m2() {                // have accees x,y and j            }        }    }}

Viewing latest article 4
Browse Latest Browse All 15

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>