方法名相同,参数不同,或参数个数相同参数类型不同
package DemoArea; public class area { private int A; private int B; private String Color; public int setarea( int a ,int b){ A=a; B=b; return a+b; } public void setarea(String col){ Color=col; } double area(){ return A*B; } public void show() { // TODO Auto-generated method stub System.out.println("颜色是"+Color); } }
package DemoArea; public class Mainarea { public static void main(String[] args) { // TODO Auto-generated method stub area a=new area(); int a1_b1; a1_b1=a.setarea(3,4); a.setarea("hs"); System.out.println("面积是"+a.area()); a.show(); } }