Java Interface and Class Hierarchy

zhaozj2021-02-12  141

Public interface icsupa {

??? Public void saya ();

}

Public interface oclassupb {

??? Public void sayb ();

}

Public interface icsup extends icsupa, iClassupb {

??? public void say ();

}

// Do Not Implements Iclassupa Here!

Public class classupa {

??? public void saya () {

????? system.out.println ("Classupa Saya ()");

???}

}

// Here Classup Implements Iclassup, Which Extends Iclassupa and iClassupb.

//

// now the classup's method saya (), Which extended by classupa, is the

//Mplementation of iClassupa # Saya ().

//

// That is to say, Even though classupa.saya () is not the item of

// Iclassupa.SAYA, ITBECOMES The Implementation of iClassupa.SAYA () by ITS

// Descendant Class Classup Through "Extends Classupa Implements Iclassup".

//

// Something Interesting and Somewhat Confusing for Some Large System.

Public Class Classup Extends Classupa Implements Iclassup {

??? // no need to import the iclassupa.saya () here!

?? public void say () {

????? system.out.println ("Classup Say ()");

???}

??? public void sayb () {

????? system.out.println ("Classup Sayb ()");

???}

}

// Test My IDEA.

Public class interfaceAnDClasstest {

??? public static void main (String [] args) {

????? Object cu = new classup ();

????? f i (cu instanceof classupa) {

????????? Classupa mycu = (classupa) cu;

???????? mycu.saya ();

??????}

???}

}

// Result:

// Classupa Saya ()

// Copyright NOTICE:

// you are authorized to copy and use this example

// Non-Commercial Use, Under The Condition That You Keep? The Article's CopyRight

// NOTICE UNCHANGED and SHIP with the NOTICE.

// this article is firstly posted at

//

Http://blog.9cbs.net/reve//******************************************************* ************************************************

* Copyright (C) 2002, 2004 IDSignet.

? * All Rights Reserved.

? * http://www.idsignet.com

? *

? * Created on Jul 6, 2004

? ********************************************************** ***************************** /

/ **

? * @Author Janyckee Joz

? * /

转载请注明原文地址:https://www.9cbs.com/read-6992.html

New Post(0)