概念
注意事項
(
(
(
(
如果只是返回類型不一樣
如果只是控制訪問修飾符號不一樣
Overloaded的方法是可以改變返回值的類型
概念
注意事項
(
(
例
Overrride實例
class A{
public int getVal(){
return(
}
}
class B extends A{
public int getVal(){
return(
}
}
public class override {
public static void main(String[] args) {
B b = new B();
A a= (A)b;//把 b 強 制轉換成A的類型
int x=a
System
}
}
Overload實例
package com
//Demostrate method voerloading
class OverloadDemo {
void test(){
System
}
void test(int a){
System
}//end of Overload test for one integer parameter
void test(int a
System
}
double test(double a){
System
return a*a;
}
}
class Overload{
public static void main(String[] args) {
OverloadDemo ob = new OverloadDemo();
double result;
ob
ob
ob
result = ob
System
}
}
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20248.html