Java Learning notes--inheritance issues in exceptions

Source: Internet
Author: User

<span style= "FONT-SIZE:18PX;" ></span>
/*
This example is an exception in the inheritance of the problem, when bexception inherit Aexception, the parent class throws Aexception, then the child class can only throw aexception or bexception, and not throw other exceptions, because the subclass can not be more than the parent class " There is a problem. " Here is an example:

*/

<span style= "FONT-SIZE:18PX;" >class Aexception extends Exception{}class bexception extends Aexception{}class fu{public void Show () throws Aexceptio N{}}class Zi extends fu{public void Show () throws bexception//or throw bexception{}}class exceptiondemo3{public static void M Ain (string[] args) {Try{fu f = new Fu (); F.show ();} catch (aexception E)//can only be thrown aexception{}try{zi z = new Zi (); Z.show ();} catch (aexception E)//When a method in a subclass throws Bexception this also throws bexception{}try{fu F = new Zi (); F.show ();} catch (aexception E)//can only throw aexception, because polymorphic {}}}</span>


Java Learning notes--inheritance issues in exceptions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.