Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the conditions under which java rewriting occurs?

Shulou Source: shulou.com Published: 2022-05-31 10:52:40 10月03日 Update

This article mainly introduces the relevant knowledge of what the conditions for java rewriting are, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this java rewriting condition. Let's take a look at it.

Occurrence condition

1. The method name is the same

2. The parameter list of the method is the same (return type and data type)

3. The return value of the method is the same.

4. An overridden method cannot throw a new exception or check exceptions more widely than the check exception declared by the rewritten method.

But fewer, more limited, or no exceptions can be thrown.

Example

Import java.io.*; public class Test {public static void main (String [] args) {Animal h = new Horse (); try {h.eat ();} catch (Exception e) {}} class Animal {public void eat () throws Exception {System.out.println ("Animal is eating.") Throw new Exception ();}} class Horse extends Animal {public void eat () throws IOException {System.out.println ("Horse is eating."); throw new IOException ();}} this is the end of the article on "what are the conditions for java rewriting?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "what are the conditions for java rewriting". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Conditions methods same knowledge content articles types checks values parameters examples easy to operate data articles easy to understand more limited see industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Apple Xiaomi vpn OPPO Reno