1 2 Previous Next 22 Replies Latest reply: Aug 16, 2008 4:11 PM by 796440 RSS

    OO:overloading and overriding in tandem..Interesting one

    807589
      Assume Dog IS-A Animal

      class test {
      public static void main(String[] args){
      Animal a = new Dog();
      foo(a);
      }

      void foo(Dog d){
      d.printme();
      }

      void foo(Animal a){
      a.printme();
      }

      }//end of class test

      class Animal{
      void printme(){
      System.out.println("i am in animal");
      }
      }//end of class animal

      class Dog{
      void printme(){
      System.out.println("i am in Dog");
      }
      }//end of class dog
      ---
      Question:what will it print and explain how briefly u arrived at that result? (I assume u fix some obvious compile time errors(missing ; etc) as this is just a rough snippet)
      NOTES-----------
      1.Overloading has to do with reference type
      2.Overriding has to do with the object to which it actually points
        1 2 Previous Next