Java - What is the output: overload method

Question

What is the output of the following code.

import java.util.Date;

public class Main {

  public static void hello(Object o) {
    System.out.println("call to Object");
  }

  public static void hello(Date d) {
    System.out.println("call to Date");
  }

  public static <T> void methodCaller(T t) {
    hello(t);
  }

  public static void main(String[] args) {
    methodCaller(new Date());
  }
}


Click to view the answer

call to Object

Demo

import java.util.Date;

public class Main {

  public static void hello(Object o) {
    System.out.println("call to Object");
  }//from   w  ww .j  av a  2s  .com

  public static void hello(Date d) {
    System.out.println("call to Date");
  }

  public static <T> void methodCaller(T t) {
    hello(t);
  }

  public static void main(String[] args) {
    methodCaller(new Date());
  }
}

Related Topic