Saturday, May 19, 2018

What is Anonymous Inner Class

Leave a Comment

Anonymous inner class


It is an inner class whose name is hidden in the outer class and for which only one object is created. An inner class is where you define one class within another. You might do this where one class is tightly coupled to another class and there is no point in defining a new class.





A Sample example of inner class



// Inner class
private class Inner {
Inner() {}

public void innerMethod() {
// Do something.
}
}
}

// Inner class
private class Inner {
Inner() {}


public void innerMethod() {
// Do something.
}
}
}


Note: An inner class is a non-static nested class. It has access to all of the variables and methods of its outer class and may refer to them directly in the same way that other non-static members of the outer class do.  Thus , an inner class is fully with in the scope of its enclosing class.
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment