Home > Mobile >  Access a method inside a static inner class
Access a method inside a static inner class

Time:01-05

Is it possible to access a normal method which is inside a static inner class ? If yes please tell me how to do it I have attached the java code that I have practiced.

class outer {
    public static class inner {
        public void show() {
            System.out.println("Im inside void show method!!!!!!!!");
        }
    }
}

public class Sampelproject {
    public static void main(String[]args) {
        outer obj = new outer();
        outer.inner.show();   
    }
}

I have tried the above code it is throwing me error.

CodePudding user response:

The inner#show() method is not a static method.

You should make it static if you want to do something like ClassName.methodName()

  • Related