Try single level inheritance with Super Class as Final



Define a Super
Class as final and try to show single level inheritance. 








final
class A


 {


  protected double l,b;





  A(double x,double y)


   {


    l=x;


    b=y;


   }


  double CalArea()


    {


     System.out.println("Class A");


     return (l*b);


    }


 }





class
B extends A


 {


  B(double x,double y)


   {


    super(x,y);


   }


  double CalArea()


    {


     System.out.println("Class B");


     return (l*b);


    }


 }


class
Sk15


 {


  public static void main(String args[])


   {


    B obj=new B(5.5,6.5);


    double a= obj.CalArea();


    System.out.println("Area= "+a);


    }


 }


Compile:


D:\>javac
Sk15.java


Error:


D:\SK>javac
Sk15.java


Sk15.java:17:
cannot inherit from final A


class
B extends A


                ^




1
error


0 Comments