java very very imp questions

Is it possible to write method inside method?
Answer:

it is possible to write a method inside a method by using method local inner classes. 

public void display() {
    System.out.println("This is outerclass method.");
                
    class Inner{
        
         public void displayInner() {
            System.out.println("innerclass method");
        }       
}
         Inner objC = new Inner();
         objC.displayInner();
         }
}
class MethodeInsideMethod {
         public static void main(String[] args) {
                 Outer objC = new Outer();
                 objC.display();
         }
}
Output:
This is outerclass method.
innerclass method
 


Comments