Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Given a method that doesn declare any exceptions, can I override that method in a subclass to throw an exception?

0
Posted

Given a method that doesn declare any exceptions, can I override that method in a subclass to throw an exception?

0

Ans : No; subclasses must honor the API contract established by their superclasses, and this includes the types of checked exceptions that a method can throw. An API (application programming interface) establishes a contract of intent, not just of form or interpretation. To borrow terminology from linguistics and philosophy, an API contract involves both extension and intension: the boundaries of the current state of the world (extension) as well as the intended boundaries for other possible states of the world (intension: possible future implementations). In object-oriented programming, a common source of “possible future implementations” is subclassing from an existing class in an API. A method defines a contract for any subclass method that would override it; it constrains possible implementations that a subclass could provide. In Java, the bare minimum contract for a method’s inputs and outputs is the following: • A method’s parameter list is fixed; an overriding method in a subcla

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123