Java笔记——方法重载

package tmp;

public class Calculate {

	public static void main(String[] args) {
		calculated x1=new calculated(1.0);
		calculated x2=new calculated(1,1);
		System.out.println("半径为1的圆的面积:"+x1.get_Area()+"  边长为1的正方形面积:"+x2.get_Area(0));
	}

}

class calculated{
	final double pi=3.14d;
	public double r=1.0d;
	public int l;
	public int w;
	public calculated(double r){
		this.r=r;
	}
	public calculated(int l,int w){
		this.l=l;
		this.w=w;
	}
	public double get_Area(){
		double area=pi*r*r;
		return area;
	}
	public int get_Area(int k){
		return l*w;
	}
}


学习要点:1、方法重载;2、一个类里面只能有一个public Class

你可能感兴趣的:(JAVA基础知识)