Skip to content

Commit 3587532

Browse files
committed
2 parents 9999321 + c1b0ed5 commit 3587532

1 file changed

Lines changed: 26 additions & 30 deletions

File tree

readme.md

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,41 +1093,37 @@ public class Dog implements Animal {
10931093
An inner class in Java is a class that is defined within another class. Inner classes can access the members (
10941094
including private members) of the outer class. There are four types of inner classes in Java:
10951095

1096-
-
1097-
1. **Member Inner Class**: A class defined within another class.
1098-
-
1099-
2. **Static Nested Class**: A static class defined within another class.
1100-
-
1101-
3. **Local Inner Class**: A class defined within a method.
1102-
-
1103-
4. **Anonymous Inner Class**: A class without a name, defined and instantiated in a single statement.
1096+
- 1. **Member Inner Class**: A class defined within another class.
1097+
- 2. **Static Nested Class**: A static class defined within another class.
1098+
- 3. **Local Inner Class**: A class defined within a method.
1099+
- 4. **Anonymous Inner Class**: A class without a name, defined and instantiated in a single statement.
11041100

11051101
Inner classes are useful for grouping related classes together, improving encapsulation, and reducing code complexity.
1106-
-
1102+
They can be used to implement callbacks, event handling, and other design patterns.
11071103

1108-
Here is an example of a member inner class:
1109-
1110-
```java
1111-
public class OuterClass {
1112-
private int outerField = 10;
1113-
1114-
class InnerClass {
1115-
void display() {
1116-
System.out.println("Outer field value: " + outerField);
1104+
Here is an example of a member inner class:
1105+
1106+
```java
1107+
public class OuterClass {
1108+
private int outerField = 10;
1109+
1110+
class InnerClass {
1111+
void display() {
1112+
System.out.println("Outer field value: " + outerField);
1113+
}
1114+
11171115
}
1118-
1119-
}
1120-
1121-
public static void main(String[] args) {
1122-
OuterClass outer = new OuterClass();
1123-
OuterClass.InnerClass inner = outer.new InnerClass();
1124-
inner.display();
1116+
1117+
public static void main(String[] args) {
1118+
OuterClass outer = new OuterClass();
1119+
OuterClass.InnerClass inner = outer.new InnerClass();
1120+
inner.display();
1121+
}
1122+
11251123
}
1126-
1127-
}
1128-
```
1129-
1130-
In this example, `InnerClass` is an inner class within `OuterClass` and can access the `outerField` of `OuterClass`.
1124+
```
1125+
1126+
In this example, `InnerClass` is an inner class within `OuterClass` and can access the `outerField` of `OuterClass`.
11311127

11321128
- **61 . What is a static inner class?**\
11331129
A static inner class in Java is a nested class that is defined as a static member of the outer class. It does not have

0 commit comments

Comments
 (0)