Try It Yourself: overloading

  1. Which two of the following declarations have the same method signature?
    public void test(int  a, String s)
    
    public void test(int  a, String s, int b)
    
    public int  test(int  a, String s)
    
    public void test(long a, String s)
    
    
  2. Which two of the following declarations have the same method signature?
    public  char mystery(int a, double b, int c)
    
    public  void mystery(int a, double b, float c)
    
    private void mystery(int q, double r, float s)
    
    public  void mystery(int a, double b, double c)
    
    
  3. Given the following method defintions (all in the same class):
    public void doIt(int in1, int in2) {
    	System.out.println("*** " + (in1 + in2) + " ***");
    }
    public void doIt(int in1, String in2) {
    	System.out.println("!!! " + (in1 + in2) + " !!!");
    }
    public void doIt(double in1, int in2) {
    	System.out.println("+++ " + (in1 * in2) + " +++");
    }
    
    What is the output for the code fragment below:
    for (int i = 0; i < 7; i++) 
    	if (i % 3 == 0)
    		doIt(0, "three");
    	else if (i % 3 == 1)
    		doIt(1, i);
    	else
    		doIt(2.0, i);