Static class in java

In Java, only nested classes can be declared as static classes.Static classes do not need the reference of the outer class. They act like an outer class within themselves. Normal non-static nested classes, on the other hand, need reference of the outer class.

In other words "In other words, static classes are independent of the outer class, while other inner classes are dependent on the outer class".

Example:

import java.lang.*;
class  Intrest
{    
    // Nested  class
	 class  Simple
	 {		 
		 double Calculate(double amt,double rate,double time)
		 {
		   double  i=(amt*rate*time)/100;
		   return(i);
		 }     
	 
	 }	 

	static class  Compound
	 {	 
		 double Calculate(double amt,double rate,double time)
		 {
		   double  i=(amt* Math.pow( (1+(rate/100)), time)) -amt;
		   return(i);
		 }
	 
	 }
	
}
public class soft 
{	
	public  static void main(String  args[])
	{
		Intrest  outer= new Intrest(); 
		
		Intrest.Simple si=  outer.new Simple();
		double  r= si.Calculate(1000, 5, 2);
		System.out.println("Simple Interest::"+r);
				
		//you can create an object for the static class only by accessing it through the outer class
		
		Intrest.Compound ci=  new Intrest.Compound(); 
		r= ci.Calculate(1000, 5, 2);
		System.out.println("Compound Interest::"+r);
			
	}

}

Output:

Simple Interest::100.0
Compound Interest::102.5

Static method in java

static methods in Java can be called without creating an object of class.
The main method is a static method:
public static void main(String[] args) {}

import java.lang.*;
class  Interest
{    	 
	static  double Calculate_SI(double amt,double rate,double time)
		 {
		   double  i=(amt*rate*time)/100;
		   return(i);
		 }     
	 
	 static	 double Calculate_CI(double amt,double rate,double time)
		 {
		   double  i=(amt* Math.pow( (1+(rate/100)), time)) -amt;
		   return(i);
		 }	
}
public class soft 
{	
	public  static void main(String  args[])
	{		 
		  // No Instance created of Interest class
		double  r= Interest.Calculate_SI(1000, 5, 2);   
		System.out.println("Simple Interest::"+r);
		
	 
		r= Interest.Calculate_CI(1000, 5, 2);
		System.out.println("Compound Interest::"+r);
	
	}
}

Output is:

Simple Interest::100.0
Compound Interest::102.5