Super Class Example in Java


Here is the simple program for printing basic example using Super Class in Java.

Source Code

import java.io.*;
import java.util.Scanner;
class single
{
  //www.tutorjoes.com
  public static void main(String args[])
  {
   fun2 o1 =new fun2(250,100,10,20);
   o1.add();
   o1.sub();
  }
}
class fun1
{
  private int a,b;
  fun1(int x,int y)
  {
   a=x;
   b=y;
  }
  public void add()
  {
    System.out.print("\nTotal : "+(a+b));
  }
}
class fun2 extends fun1
{
  private int a,b;
  fun2(int x,int y,int x1,int y1)
  {
    super(x1,y1);
    a=x;
    b=y;
  }
  public void sub()
  {
    System.out.print("\nDiffrence : "+(a-b));
  }
}
To download raw file Click Here

Output

Total : 30
Diffrence : 150


Learn All in Tamil © Designed & Developed By Tutor Joes