- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are method local inner classes in Java?
In Java, we can write a class within a method and this will be a local type. Like local variables, the scope of the inner class is restricted to the method.
A method-local inner class can be instantiated only within the method where the inner class is defined. The following program shows how to use a method-local inner class.
Example
public class OuterClass { public void display(){ int num = 23; class Inner{ public void print() { System.out.println("This is method inner class "+num); } } Inner obj = new Inner(); obj.print(); } public static void main(String args[]){ OuterClass outer = new OuterClass(); outer.display(); } }
Output
This is method inner class 23
- Related Articles
- What are inner classes in Java?
- What are anonymous inner classes in Java?
- Can a method local inner class access the local final variables in Java?
- How are anonymous (inner) classes used in Java?
- Local inner class in Java
- What is the difference between static classes and non-static inner classes in Java?
- How many types of anonymous inner classes are defined in Java?
- Why do we need inner classes in Java?
- What are Java classes?
- Local Inner Class in C#
- What are final classes in Java?
- What are abstract classes in Java?
- What are wrapper classes in Java?
- What are I/O classes in Java?
- What are Java parent and child classes in Java?

Advertisements