对类默认方法的应用
package hong;
import java.util.Scanner; //引入java.util,Scanner类接口
public class Changfx { //定义公共类Changfx
private int chang;
private int kuan;
public static void main(String[] args) {
// TODO 自动生成的方法存根
int mianji, zhouchang;
Changfx changfx =new Changfx();
Scanner sc=new Scanner(System.in);
System.out.println("输入长方形的长:");
changfx.chang = sc.nextInt();
System.out.println("输入长方形的宽:");
changfx.kuan =sc.nextInt();
mianji=Changfx.getMianji();
zhouchang=2*(changfx.chang+changfx.kuan);
System.out.println("长方形的面积:mianji=chang*kuan="+mianji);
System.out.println("长方形的周长:zhouchang=2*(chang+kuan)="+zhouchang);
}
private static int getMianji() {
// TODO 自动生成的方法存根
return 0;
}
}
运行结果: