Thực hiện phân cấp Shape thể hiện trong hình trên. Mỗi hình dạng hai chiều nên có phương pháp getArea () để tính toán diện tích của nó (ví dụ như diện tích hình tròn là pi * r2).
Mỗi hình dạng ba chiều nên chứa getArea () và getVolume () phương pháp để tính toán diện tích bề mặt và khối lượng tương ứng.
Tạo một chương trình sử dụng một loạt các tài liệu tham khảo Shape để đối tượng của mỗi lớp cụ thể trong hệ thống phân cấp. Chương trình phải in các đối tượng mà mỗi phần tử mảng đề cập.
Cũng trong vòng lặp xử lý tất cả các hình dạng trong mảng đó, xác định xem mỗi hình dạng là một hình dạng hai chiều hoặc hình dạng ba chiều. Nếu một hình dạng là một trong hai chiều, hiển thị khu vực của mình. Nếu một hình dạng là ba một chiều, hiển thị diện tích và khối lượng của nó.
đang được dịch, vui lòng đợi..