Java Inner Example -10 Program

  1. Nested classes represent a particular type of relationship that is it can access all the members (data members and methods) of the outer class, including private.
  2. Nested classes are used to develop more readable and maintainable code because it logically group classes and interfaces in one place only.
  3. Code Optimization: It requires less code to write.

Static Inner Class

An inner class can also be static, which means that you can access it without creating an object of the outer class:

Access Outer Class From Inner Class

One advantage of inner classes, is that they can access attributes and methods of the outer class:

PROGRAM 5: Access Outer Class From Inner Class example.

CODE:

Java Anonymous inner class

Java anonymous inner class is an inner class without a name and for which only a single object is created. An anonymous inner class can be useful when making an instance of an object with certain “extras” such as overloading methods of a class or interface, without having to actually subclass a class.

Java Local inner class

A class i.e., created inside a method, is called local inner class in java. Local Inner Classes are the inner classes that are defined inside a block. Generally, this block is a method body.

data is 30
inside outerMethodx= 98
inside inner class Methodinside outerMethodThank you ,I hope this program tutorial clear to you .If any queries please comment.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store