Static inner class

  • Eclipse: Oxygen
  • Java: 1.8

We have seen the inner classes. The inner classes can access the outer variables. The static inner class can only access the static members. Hence the non-static members when tried to access give an error.

A static class in Java, created within a class is called a static nested class. It is unable to access non-static data methods and members. It can be accessed by outer class name. You can access the static data members of the outer class, including private ones.

 

Output

Testing inner class method.
0

Output

Testing inner class method.
0

Here the properties of the inner static class are shown and also how they can access the outer class variables and methods is shown. After the lecture user will learn how we can use this type of classes in our daily programs.

Output

Value of inner class variable: 0
Testing inner class method.

Output

Value of inner class variable: 0
Testing inner class method.

Contributed by: Poonam Tomar


Full stack Java Developer

   Buy me a coffee!

 

PayTM QR (INDIA)

Download file

Leave a Reply

avatar
  Subscribe  
Notify of
Close Menu