1 /*2 * Exception precautions: 3 * A: When a subclass overrides a parent class method, the child class's method must throw the same exception or subclass of the parent exception. (father is broken, son can not be worse than father)4 * B: If the parent class throws more than one exception, when the subclass overrides the parent class, it can only throw the same exception or a subset of his, the subclass cannot throw exceptions that the parent class does not have5 * C: If the overridden method does not throw an exception, then the method of the subclass must not throw an exception, if there is an exception in the subclass method, then the subclass can only try, not throws6 */7 Importjava.text.ParseException;8 ImportJava.text.SimpleDateFormat;9 Importjava.util.Date;Ten Public classExceptiondemo { One A } - - classFu { the Public voidShow ()throwsException { - } - - Public voidmethod () { + } - } + A classZiextendsFu { at @Override - Public voidShow ()throwsArithmeticException { - - } - - @Override in Public voidmethod () { - //String s = "2014-11-20"; to //SimpleDateFormat sdf = new SimpleDateFormat (); + //Date d = sdf.parse (s); - //System.out.println (d); the } *}
Considerations for Java 19-11 Exceptions