麻煩大神幫我指點一下一下這段代碼該怎么改?謝謝
父類:
package com.imocc
public abstract class shape {
public abstract void l();
public abstract void s();
}
子類:rectangle
package com.imocc;
public class rectangle extends shape {
public void l(int a,int b){
System.out.println("長方形的周長是:"+(a+b)*2);
}
public void s(int a,int b){
System.out.println("長方形的面積是:"+a*b);
}
}
子類circle:
package com.imocc;
public class circle extends shape {
double π=3.14;
public void l(int r){
double m=2*π*r;
System.out.println("圓形的周長是:"+m);
}
? ? public void s(int r){
? ? double n=π*r*r;
? ? System.out.println("圓形的面積是:"+n);
? ? }
}
inital;
package com.imocc;
import java.util.Scanner;
public class inital {
public static void main(String[] args) {
shape rec=new rectangle();
Scanner input=new Scanner(System.in);
System.out.println("請輸入長方形的長a:");
int a=input.nextInt();
System.out.println("請輸入長方形的寬b:");
int b=input.nextInt();
rec.l(a,b);
rec.s(a,b);
shape c=new circle();
Scanner input2=new Scanner(System.in);
System.out.println("請輸入圓形的半徑r:");
int r=input2.nextInt();
c.l(r);
c.s(r);
// TODO Auto-generated method stub
}
}
2018-08-19
Java抽象類中的抽象方法的參數(shù)對應(yīng)的子類的方法的參數(shù)必須一致