Interface and abstract class

zhaozj2021-02-16  81

Package com.dzl.test;

Import java.io. *; import java.util. *;

Interface myinterface {// constant public static final int myval = 123; // method public void f ();} Abstract class myabstract implemens myinterface {// implement interface method public void f () {system.out.println ("abstract" } // Custom method public void f2 () {system.out.println ("f1");}}}}}} Class A Implements MyInterface {// Implement Interface Method PUBLIC VOID F () {System.out.println (" a "); system.out.println (myval);}}}}}}}}}}}}}}}}}}} Class B Extends myabstract {// Implement abstract class method public void f1 () {system.out.println (" b ");}}

Public class test {public static void main (string args []) {// instantiated class a a aa = new a (); myinterface test = aa; test.f (); // -------- ---- // Instantiated class B b bb = new b (); bb.f (); bb.f1 (); bb.f2 (); system.out.println (bb.myval);}}

Result: A123ABSTRACTBF1123

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

New Post(0)