- /** Defines squares*/
- import java.awt.* ;
// Needed for Color
- public class Square {
- double
side1, side2 ; // Side in inches
- Color color ;
-
// Constructors are overloaded
-
Square ( ) {
- side1 = 4.0
;
- side2 = 4.0
;
- }
-
-
Square ( Color c ) {
- side1 = 2.0
;
- side2 = 2.0
;
- color = c ;
- }
-
- public double
areaCalculator ( ) {
-
return ( side1 * side2 ) ;
- }
- }
|
- /** Defines red squares.*/
- import java.awt.* ;
- public class RedSquare
extends Square {
- RedSquare ( ) {
- super (Color.RED)
;
- }
-
// Method
below overrides method
-
// with same name in
super class
- public double
areaCalculator ( ) {
-
return ( side1 * side2 / 12.0 ) ;
- }
- }
|