接口

package oo.day06;
//interface演示
public class InterfaceDemo {
public static void main(String[] args) {
//Inter6 o = new Inter6(); //编译错误,接口不能被实例化
Foo o1 = new Foo();
Inter6 o2 = new Foo(); //向上造型
Inter5 o3 = new Foo(); //向上造型

/*
* 接口练习:
* 1.定义接口Inter1,包含常量NUM以及方法a()
* 2.定义接口Inter2,包含b()和c()
* 定义类Coo,实现Inter2接口
* 3.定义接口Inter3,包含d()
* 定义类Doo,实现Inter2和Inter3接口
* 4.定义抽象类Eoo,包含抽象方法e()
* 定义类Foo,继承Eoo并实现Inter2和Inter3接口
* 5.定义接口Inter4,继承Inter3接口,并包含f()
* 定义类Goo,实现Inter4接口
* 6.main()方法中:
* Inter4 o1 = new Inter4();----???
* Inter4 o2 = new Goo();-------???
* Inter3 o3 = new Goo();-------???
*/
}
}

interface Inter5{
void a();
}
interface Inter6 extends Inter5{
void b();
}
class Foo implements Inter6{
public void b(){}
public void a(){}
}


interface Inter3{
void a();
}
interface Inter4{
void b();
}
abstract class Doo{
abstract void c();
}
class Eoo extends Doo implements Inter3,Inter4{
public void a(){}
public void b(){}
void c(){}
}

interface Inter2{
void a();
}
class Coo implements Inter2{
public void a(){}
}

interface Inter1{
public static final int NUM=5;
public abstract void show();

double PI = 3.14159;//默认public static final
void sayHi(); //默认public abstract

//public void say(){} //编译错误
//public int a; //编译错误
}

原文地址:https://www.cnblogs.com/xiaziteng/p/4731406.html