lab8 finished
This commit is contained in:
39
lab/lab8/Question6/Start.java
Normal file
39
lab/lab8/Question6/Start.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Answers the question.
|
||||
*
|
||||
* Question3:
|
||||
*
|
||||
* - Q: What is the problem with the resize method of the Shape calss? How do
|
||||
* you solve this problem?
|
||||
*
|
||||
* - A: The resize method of the Dot class is inherited from the Shape class.
|
||||
* which does not have a throw Exception declared. We can solve this problem by
|
||||
* declaring the resize method in the Shape class as a throw Exception.
|
||||
*
|
||||
* - Q: Do you need to change the resize method of the Circle class then?
|
||||
*
|
||||
* - A: No, we do not need to change the resize method of the Circle class.
|
||||
*
|
||||
* - Q: Does the Square class need its own area and resize method or not?
|
||||
*
|
||||
* - A: No, but it depends. Currently the Square.area and Square.resize methods
|
||||
* return the correct values. But in the future, if we want to change the
|
||||
* Rectangle.area and Rectangle.resize methods, the Square class may give the
|
||||
* wrong values. So it is better to have its own area and resize methods.
|
||||
*
|
||||
* - Q: What is then the problem for the Square class?
|
||||
*
|
||||
* - A: No problem. The area method is overloaded. But the resize method in
|
||||
* Square can set different values for the width and height. So it is better to
|
||||
* have its own resize methods.
|
||||
*/
|
||||
|
||||
public class Start {
|
||||
public static void main(String[] args) {
|
||||
Shape.testShape();
|
||||
Circle.testCircle();
|
||||
Dot.testDot();
|
||||
Rectangle.testRectangle();
|
||||
Square.testSquare();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user