Nested Class

The Java programming language allows to define a class within another class. Such a class is called a nested class and is defined as

class OuterClass 
{
...

class NestedClass 
{
...
}

}

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);
		 }	 
	 }	 
	 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);
		
		Intrest.Compound ci=  outer.new Compound(); 
		r= ci.Calculate(1000, 5, 2);
		System.out.println("Compound Interest::"+r);
		
	}

}

output

 Simple Interest::100.0

Compound Interest::102.5