糾錯(cuò)完善后的Java復(fù)習(xí)易忘題1:聲明形狀類,形狀有正方形,長(zhǎng)方形,重載其構(gòu)造方法

一些是我糾錯(cuò)完善后,用來復(fù)習(xí)的Java易忘題!
/* 6.聲明形狀類,形狀有正方形,長(zhǎng)方形,重載其構(gòu)造方法,如果傳入一個(gè)參數(shù)是正方形,2個(gè)參數(shù)是長(zhǎng)方形,聲明計(jì)算形狀面積的方法,打印其面積 */
package a;
class chongzai {
int chang;
int kuan;
int bianchang;
public chongzai(int chang) {
this. chang=chang;
}
public chongzai(int chang,int kuan) {
this. chang=chang;
this. kuan=kuan;
}
/*或public chongzai(int longs, int wide) {
System. out. println("這是一個(gè)長(zhǎng)方形");
countArea (longs, wide) ;
}*/
public static void countArea(int bianchang) {
System. out. println("這是一個(gè)正方形,面積:"+bianchang *bianchang);}
public static void countArea(int? chang, int kuan){
System. out. println("這是一個(gè)長(zhǎng)方形,面積:"+ chang *kuan);
}
public static void main(String[] args) {
chongzai.countArea(2);
chongzai.countArea(2,3);
/*或countArea(2);
countArea(2,3);*/
}
}
