6 Method Overriding in Java - Javatpoint
6 Method Overriding in Java - Javatpoint
Content Menu ▼
. class Vehicle{
. void run(){System.out.println("Vehicle is running");}
. }
. class Bike extends Vehicle{
.
. public static void main(String args[]){
. Bike obj = new Bike();
. obj.run();
. }
. }
http://www.javatpoint.com/methodoverridinginjava 1/4
8/14/2015 Method Overriding in Java javatpoint
Test it Now
Output:Vehicle is running
. class Vehicle{
. void run(){System.out.println("Vehicle is running");}
. }
. class Bike2 extends Vehicle{
. void run(){System.out.println("Bike is running safely");}
.
. public static void main(String args[]){
. Bike2 obj = new Bike2();
. obj.run();
. }
Test it Now
http://www.javatpoint.com/methodoverridinginjava 2/4
8/14/2015 Method Overriding in Java javatpoint
. class Bank{
. int getRateOfInterest(){return 0;}
. }
.
. class SBI extends Bank{
. int getRateOfInterest(){return 8;}
. }
.
. class ICICI extends Bank{
. int getRateOfInterest(){return 7;}
. }
. class AXIS extends Bank{
. int getRateOfInterest(){return 9;}
. }
.
. class Test2{
. public static void main(String args[]){
. SBI s=new SBI();
. ICICI i=new ICICI();
. AXIS a=new AXIS();
. System.out.println("SBI Rate of Interest: "+s.getRateOfInterest());
. System.out.println("ICICI Rate of Interest: "+i.getRateOfInterest());
. System.out.println("AXIS Rate of Interest: "+a.getRateOfInterest());
. }
. }
Test it Now
Output:
SBI Rate of Interest: 8
ICICI Rate of Interest: 7
AXIS Rate of Interest: 9
← prev next →
http://www.javatpoint.com/methodoverridinginjava 4/4