Site icon DataFlair

Java Program For final Keyword

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Program 1

package testcoreproject;
import java.awt.*;
 class Base1
{
      public static final float PI=3.14f;
      int factorial(int n)
      {
            int f=1;
            while(n!=0)
            {
                f=f*n;
                n--;
            }
            return f;
      }
}
class Derived1 extends Base1
{
    float area(float r)
    {
        float A;
        A=PI*r*r;
        return A;
    }
}

public class TestFinal 
{
    public static void main(String[] args) 
    {
        Base1 B=new Base1();
        System.out.println(B.factorial(5));
        //System.out.println(D.area(1.1f));
    }
}

 

Exit mobile version