SuperClasses are Great II

How can we improve our current class structure?right_triangle_rectangle

 

 

 

 

 

 

 

We are going to create a second “Generation” of classes and will denote this change by appending a ‘2’ to the names of all classes in this “generation”

right_triangle_extends_polygon

 

Class: Polygon2 (superclass of Triangle2, Rectangle2)  Polygon2download-bttn

 

Constructor 

public Polygon2(int _col, double _width, double _height, int _sides)

instance Variables

  • private int color;
  • private int numSides
  • protected double width;
  • protected double height

Methods

  • public int getColor()
  • public double getWidth()
  • public double getHeight()

Class: Rectangle2 extends Polygon2  Rectangle2download-bttn

instance Variables

None needed (see superclass)

Accesor Methods //override each of the superclass

  • public double getArea(); //returns the area of the triangle

Class: RightTriangle2 extends Polygon2  RightTriangle2download-bttn

instance Variables

None needed (see superclass)

Accesor Methods //override each of the superclass

  • public double getArea(); //returns the area of the triangle
  • public double getHypotenuse()

InteractiveMath2   InteractiveMath2download-bttn

 

Next: What is inherited?