package
method;
import java.awt.Container;
import javax.swing.JApplet;
import javax.swing.JTextArea;
// ——在同一个类中可以声明多个相同名称的方法。
public class MethodOverload extends JApplet ... {
public void init()...{
JTextArea outputArea = new JTextArea();
Container container = getContentPane();
container.add(outputArea);
outputArea.setText("The square of integer 7 is"+ square(7)+" The square of double 7.5 si"+square(7.5));
}
private int square(int intValue)...{
System.out.println("Called square with int argument:"+intValue);
return intValue * intValue;
}
private double square(double doubleValue) ...{
System.out.println("Called square with double argument:"+doubleValue);
return doubleValue * doubleValue;
}
}
import java.awt.Container;
import javax.swing.JApplet;
import javax.swing.JTextArea;
// ——在同一个类中可以声明多个相同名称的方法。
public class MethodOverload extends JApplet ... {
public void init()...{
JTextArea outputArea = new JTextArea();
Container container = getContentPane();
container.add(outputArea);
outputArea.setText("The square of integer 7 is"+ square(7)+" The square of double 7.5 si"+square(7.5));
}
private int square(int intValue)...{
System.out.println("Called square with int argument:"+intValue);
return intValue * intValue;
}
private double square(double doubleValue) ...{
System.out.println("Called square with double argument:"+doubleValue);
return doubleValue * doubleValue;
}
}