interface
接口 interface
--子类通过implements来实现接口中的规范
--一个类实现接口,必须实现接口中所有的方法,并且这些方法只能是Public
--接口支持多继承
package mypro01; public interface MyInterface { //接口里只有常量和抽象方法 /*public static final*/ String MAX_GRADE="BOSS"; int MAX_SPPED=120; /*public abstract*/ public void test01(); public int test02(int a,int b); } interface Interface1{ public void test03(); }
package mypro01; public class MyClass implements MyInterface,Interface1 { @Override public void test01() { System.out.println(MyInterface.MAX_GRADE);//调用属性 System.out.println("test01"); } @Override public int test02(int a, int b) { System.out.println("test02"); return a+b; } @Override public void test03() { System.out.println("test03"); } }
package mypro01; public class Test7 { public static void main(String[] args) { /* MyInterface m1=new MyClass(); MyClass m=(MyClass)m1; */ MyClass m=new MyClass(); m.test01(); int res=m.test02(3,4); System.out.println(res); m.test03(); } }
posted on 2020-02-26 22:06 happygril3 阅读(190) 评论(0) 收藏 举报
浙公网安备 33010602011771号