Java Static Nested Class


To create a static class within a class is known as a static nested class. Static nested class access the static data members of the outer class. A static nested class cannot access instance variables and methods of the outer class.


Syntax:

class Outerclass {
   static class Innerclass {
   }
} 

Example

Java static nested class with instance method.

 public class SNestedClass{  
	static int Age=22;  
	static class Innerclass{  
		void showdata(){
        	System.out.println("Age is "+Age);
        }  
	}  
	public static void main(String args[]){  
		SNestedClass.Innerclass obj=new SNestedClass.Innerclass();  
		obj.showdata();  
	}  
} 



Onlinetpoint is optimized for basic learning, practice and more. Examples are well checked and working examples available on this website but we can't give assurity for 100% correctness of all the content. This site under copyright content belongs to Onlinetpoint. You agree to have read and accepted our terms of use, cookie and privacy policy.