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 a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.