1. Abstract
JAVA is an Object Oriented Programming (OOP) language with encapsulation as the
basis of everything in it. Everything in java is wrapped up into a single unit called Class,
which can also be nested or have a Class structure within a Class. Just like a nested if-else
structure present in JAVA, we can also incorporate a similar structure to Classes creating
Nested Classes. In this paper, we delve deeper into the concepts behind these Nested
Classes, their usage and utility and their advantages. This paper would also be focusing
on the differences among the types of Nested class and also discuss about their various
types.
2. Introduction
JAVA being a modern Object Oriented Programming (OOP) language has many features
like – a) Abstraction, b) Encapsulation, c) Inheritance, and d) Polymorphism as its core
facets. One of JAVA’s prime feature is encapsulation, wherein, all data members and
objects are wrapped up into a single unit called a Class. Objects in JAVA embody the
state (as data variables) and behavior (as methods) of real-world entities, following a
general template as defined, which is the Class. A Class having another Class within it
forms what is known as a Nested Class. A Nested Class can be overviewed as a structure
which can be used to model the complexities of the real world, where an entity many be
falling under many sub-classes, but those sub-classes are only logical to the class
immediately preceding them.
The Top level or Outer classes, are declared inside a package and are visible throughout
the package or perhaps even further depending upon the access specifier used to specify
the Outer Class. Normally, although not always, the Outer class maybe declared in their
own file, while it is mandatory for Outer classes declared public, must be defined in their
own file.
The Nested and inner classes, are declared inside an Outer class (or even a method block)
and can be visible only to outer class, or may have a wider visibility as per the scope of
the inner class set the access specifier. Besides, out own thought process of grouping
things which are alike in nature, together, helps us to conceive of Nested classes far more
easily. The main features of ease of organization and access, without having to type in
redundant code, helps Nested classes to stand out and be approached by more and more
programmers.