Printed Names:  _______________

                        _______________

                        _______________

  1.  

 

  1.  

No we cannot instantiate a Shape.

We cannot instantiate a Shap because Shape is an abstract class.

If we try, we get the following message Ï

¼§ÏDriver.java:8: Shape is abstract; cannot be instantiated
ϧÏ__myShape = new Shape ();

 

  1.  

Yes abstract classes can have instance variables (class attributes)

Yes abstract classes can have class variables (static variables)

 

  1.  

They share the attribute description which, because it’s private, cannot be accessed using super.description , but which can be accessed using the toString method.

The separate attributes are:  radius in Circle and side in Square.

 

  1. No the children of Shape are NOT required to override the toString method .

They are not required to override the toString method because it is not abstract.

 

 

  1.  

Yes, the children of TwoDimensionalShape are required to override the get Area method.

They are required to override the getArea method because it’s abstract.

 

  1.  

A good structure to use would be an array of Shape

Shape [ ] myShapes; 

myShapes = new Shape[5];

 

  1.  

An alternate structure would be an array of TwoDimensionalShape

   TwoDimensionalShape [ ]  myTwoDimensionalShapes;

   myTwoDimensionalShapes = new TwoDimensionalShape [5];

 

  1.  

The term for the java feature that allows us to declare either a TwoDimensionalShape or a Shape object and then choose to make it a Circle or a Square is  polymorphism

 

  1.  

    myShape[0] = new Circle (3.4);

    myShape[1] = new Circle (43.7);

    myShape[2] = new Circle (13.8);

    myShape[3] = new Square (5.0);

    myShape [4] = new Square (7.8);

 

  1.  

ÏÏÏPoint coordinates are: 3 and 4
ÏÏÏLine coordinates: 3, 4 and 8, 8
ÏÏÏPoint coordinates are: -1 and -5
ÏÏÏSquare of area 9.0

 

  1.  

     System.out.println (aBunchOfShapes[1]);