Need Programming Assignment Help?

Get Help with Programming Assignment in Java, C/C++, Dot Net, PHP, Database and UML Diagrams

Overriding

Java Program for Overriding

Java Program for Overriding – Overloading allows different methods to have same name, but different signatures where signature can differ by number of input parameters or type of input parameters or both.

class Animal
{
   public void move()
  {
      System.out.println("Animals can move");
   }
}

class Dog extends Animal{

   public void move(){
      System.out.println("Dogs can walk and run");
   }
}

public class TestDog
 { 
   public static void main(String args[]){
      Animal a = new Animal(); 
      Animal b = new Dog(); 

      a.move();

      b.move();//Runs the method in Dog class
   }
}

 

One Comment

Comments are closed.