0% found this document useful (0 votes)
11 views7 pages

Ashesh PDF

The document discusses nested classes in object-oriented programming, highlighting their definition, types, merits, and demerits. It explains that nested classes enhance encapsulation and readability while allowing logical grouping and improved code maintainability. However, it also notes potential downsides such as increased complexity and memory management issues.

Uploaded by

Aisha Sarkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views7 pages

Ashesh PDF

The document discusses nested classes in object-oriented programming, highlighting their definition, types, merits, and demerits. It explains that nested classes enhance encapsulation and readability while allowing logical grouping and improved code maintainability. However, it also notes potential downsides such as increased complexity and memory management issues.

Uploaded by

Aisha Sarkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

OOPS

Name > Ashesh Jyoti Majumdar


Roll > 18730622005
Subject > OOPS [PCC-CS 503]
Stream > AIML 5th Semester
Topic > Nested Class
Year > 2024
Table of Contents

Page 1: Front Page


Page 2: Table of Contents
Page 3: Introduction
Page 4: Description
Page 5: Merits
Page 6: Demerits
Page 7: Reference
Nested Class

Introduction

In object-oriented programming (OOP), a nested


class is a class defined within another class.
This concept helps in logically grouping classes
that are only used in one place, enhancing
encapsulation and readability. Nested classes are
beneficial when a class is tightly coupled with
its enclosing class, allowing the nested class to
access the private members of its enclosing
class.

Nested Class
Nested Class

Description
There are two main types of nested classes:

Static Nested Class:


Defined with the static keyword.
Does not have access to the instance variables and
methods of the enclosing class.
Can access the static members of the enclosing class
directly.

Non-static (Inner) Nested Class:


Associated with an instance of the enclosing class.
Has access to all the members of the enclosing class,
including private ones.

Types
Nested Class
Merits
Logical Grouping:
Nested classes allow for logical grouping of classes
that are only used within

Encapsulation:
Nested classes can access the private members of their
enclosing class,
which enhances encapsulation.

Namespace Management:
By nesting classes, you avoid polluting the global
namespace.

Improved Code Maintainability:


Since nested classes are encapsulated within their
enclosing classes,
changes in the nested class are less likely to affect Merits
other parts of the code.

Enhanced Readability:
Nested classes can make the code easier to understand by
showing the relationship between the nested and
enclosing classes clearly.
Nested Class

Demerits
Increased Complexity:
Nested classes can add an extra layer of complexity to
the code.

Tight Coupling:
Inner classes are tightly coupled with their enclosing
classes,
which can lead to less modular code

Memory Management Issues:


Non-static inner classes hold an implicit reference to
their
enclosing class, which can cause memory leaks if the
inner class instance outlives the outer class instance

Limited Reusability: Demerits


Nested classes, especially inner classes, are often
closely tied to the specific context of their enclosing
class.
Nested Class
References
1. Google
2. ChatGPT
3. Gemini
4. Wikepidia

You might also like