慕用7104560
2018-08-19 09:24
父类:
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
}
}
Java抽象类中的抽象方法的参数对应的子类的方法的参数必须一致
Java入门第二季 升级版
530650 学习 · 6091 问题
相似问题