Overloading is the re-use of a method name in the one class or subclass for a different method. : overloading method « Object Oriented « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Object Oriented » overloading method 
6.5.9.Overloading is the re-use of a method name in the one class or subclass for a different method.
public class MainClass {
  public static void main(String[] argv) {

    MySubclass my = new MySubclass();
    my.calc(1);
    my.calc(1.1F);

    System.out.println();
  }
}

class MyClass {
  public void calc(int i) {
    System.out.println("public void calc(int i)");
  }

}

class MySubclass extends MyClass {

  public void calc(int f) {
    System.out.println("public void calc(int f)");
  }

}
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
	The method calc(int) in the type MySubclass is not applicable for the arguments (float)

	at MainClass.main(MainClass.java:6)
6.5.overloading method
6.5.1.Method overloading
6.5.2.Be careful to recognize when a method is overloaded rather than overridden.
6.5.3.Invoking overloaded methods:
6.5.4.Method overloading and class hierarchy
6.5.5.Differences Between Overloaded and Overridden Methods
6.5.6.A difference in return type is insufficient to constitute an overload.
6.5.7.Different list of thrown exceptions is insufficient to constitute an overload.
6.5.8.A method is identified by its fully qualified class name, the method name, and the exact sequence of its argument types.
6.5.9.Overloading is the re-use of a method name in the one class or subclass for a different method.
6.5.10.Overloaded methods supplement each other; an overriding method replaces the method it overrides.
6.5.11.Overloaded methods can exist, in any number, in the same class.
6.5.12.The return type of an overloaded method may be chosen freely
6.5.13.Overloaded methods may have different return types.
6.5.14.Overloaded methods have the same name but different arguments.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.