Method Overriding Example in Java


Here is the simple program for printing basic example using Method Overriding in Java.

Source Code

//Method Overriding
import java.io.*;
import java.util.Scanner;
class override
{
  //www.tutorjoes.com
  public static void main(String args[])
  {
   sub_class o =new sub_class(10,30);
   o.display();
  }
}
class super_class
{
  int b;
  super_class(int b)
  {
    this.b=(b+10);
  }
  public void display()
  {
    System.out.print("\nSuper Class : "+b);
  }
}
class sub_class extends super_class
{
   int a;
   sub_class(int a,int b)
   {
     super(b);
     this.a=a;
   }
   public void display()
   {
     System.out.print("\nSub Class : "+a);
     System.out.print("\nSuper Class : "+b);
   }
}
To download raw file Click Here

Output

Sub Class:
Value Of A :10
Value Of B :40


Learn All in Tamil © Designed & Developed By Tutor Joes