An assigment from my class is asking me to create a function, in an extended class, that overrides its parent class' function. However, there is an exception in the parent class that is not needed for the extended class' function.
This is the parent class:
public class Rectangle{ private final Exception nonRectangleException = new Exception("Use Square"); private float height; public void setHeight(float height) throws Exception { if(getWidth().equals(height)) { throw nonRectangleException; } this.height = height; } }
The extended class is supposed to override this with its own setHeight function. It does not care if width and height are the same like the exception in the parent class (6th line in the code).
So is there a way to ignore the exception in the overwritten function, or is there another more official way to do this?
By the way, this is my first post on stackoverflow so appologies if I confused anyone with my question.
https://stackoverflow.com/questions/66083888/java-is-there-a-way-to-ignore-exceptions-in-function-with-an-override-class-fu February 07, 2021 at 10:02AM
没有评论:
发表评论