1. 程式人生 > >已知一個抽象類Shapge,該類中有一個方法GetArea。 要求定義一個Rectangle類,繼承Shape類,實現GetArea方法計算矩形面積。

已知一個抽象類Shapge,該類中有一個方法GetArea。 要求定義一個Rectangle類,繼承Shape類,實現GetArea方法計算矩形面積。

已知一個抽象類Shapge,該類中有一個方法GetArea。

要求定義一個Rectangle類,繼承Shape類,實現GetArea方法計算矩形面積。

輸入輸出說明:
輸入:
5 4
輸出:
20.0

import java.util.Scanner;
abstract class Shape{
    abstract double GetArea();
}

// Write your own code
class Rectangle extends Shape{
    int a,b;
	Rectangle(){
		
	}
	Rectangle(int a,int b){
		this.a = a;
		this.b = b;
	}

	@Override
	double GetArea() {
		// TODO Auto-generated method stub
		return (double)a*b;
	}
	
}
public class Main{
    public static void main(String[] args){
        Scanner sca = new Scanner(System.in);
        int aa = sca.nextInt();
    	int b = sca.nextInt();
        Rectangle a = new Rectangle(aa,b);
        System.out.println(a.GetArea());
    }    
}