Why Java classes are single-inheritance. The inheritance of the class, implements the interface.

Source: Internet
Author: User

Provides a single inheritance between classes and classes in Java.

There may be errors in providing multiple inheritance, such as: A class inherits two parent classes, and two parent classes have the show () method.

Class fulei1{

public void Show () {

System.out.println ("Parent Class 1");

}

}

Class fulei2{

public void Show () {

System.out.println ("Parent Class 2");

}

}

Class Zilei extends fulei1,fulei2{

public static void Main (string[] args) {

Zilei p=new Zilei ();

The call is faulted because the call is indeterminate and the Java code does not know which parent class to invoke.

P.show ();

}

}

However, there can be multiple inheritance between the interface and the interface.

Why interfaces and interfaces can inherit more, the reason, the interface method is not implemented specifically, the implementation requires subclasses to rewrite the interface of the method, all does not exist as the above-called uncertainty.

Why Java classes are single-inheritance. The inheritance of the class, implements the interface.

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.