.

Java Tutorial: Inner Classes in Java

Inner Classes in Java

classNameresiding internal to an another classNameis named as inner class

The classNamewhich is built inside an another classNameis termed as an outer class

Syntax

{`

classNameoutside_class

{

classNameinside_class

{

}

}

`}

Types

It is classified into 2 categories. They are

  • Static Nested Class
  • Non Static Nested classNamealso termed as Inner Class

Non Static Nested classNamealso termed as Inner Class

  • It offers security feature in this language.
  • It is liable to employ an inner classNameas a private. Usually it is impossible in java
  • It is also liable to retrieve the private attributes of a class

Example

The following program highlights the way of creating inner private classNameand the way of accessing it

Static Nested Class

  • It is a kind of Inner classNamewith the keyword static.
  • It is static classNameresiding within an another class
  • It is not required to create object for an outside class
  • It is not belonging to the scope of outerside classNameinstance variables and functions

Syntax

{`

classNameouterside

{

static classNameinside

{

}

}

`}

Example

inner classes in java img1
.