Java static nested classA static class is a class that is created inside a class, is called a static nested class in Java. It cannot access non-static data members and methods. It can be accessed by outer class name.
Java static nested class example with instance methodTestOuter1.java Test it NowOutput: data is 30 In this example, you need to create the instance of static nested class because it has instance method msg(). But you don't need to create the object of the Outer class because the nested class is static and static properties, methods, or classes can be accessed without an object. Internal class generated by the compilerJava static nested class example with a static methodIf you have the static member inside the static nested class, you don't need to create an instance of the static nested class. TestOuter2.java Test it NowOutput: data is 30 Next TopicNested Interface |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India