package pack1.pack2;
public class testInterface {
}
class testIn{
public static void main(String[] args) {
Angel a1=new Angel();
a1.fly();
a1.helpOthers();
}
}
interface Volant{
int fly_height=1000;
void fly();
}
interface Honest{
void helpOthers();
}
class Angel implements Volant,Honest{
@Override
public void helpOthers() {
System.out.println("我是天使,喜欢扶老奶奶过马路");
}
@Override
public void fly() {
System.out.println("我是天使,飞呀飞呀");
}
}
package pack1.pack2;
public class TestInterface2 {
public static void main(String[] args) {
ji j1=new ji();
j1.testA();
j1.testc();
}
}
class ji implements C{
@Override
public void testc() {
System.out.println("ccc");
}
@Override
public void testA() {
System.out.println("aaa");
}
@Override
public void testB() {
System.out.println("bbb");
}
}
interface A{
void testA();
}
interface B{
void testB();
}
interface C extends A,B{
void testc();
}
接口中的默认方法 default
package pack1.pack2;
public class testInterface3 {
public static void main(String[] args) {
TestA t1=new TestA();
t1.moren1();
A1.staticMethod();//接口名称调用
TestA.staticMethod();//实现类的静态方法
TestB tb=new TestB();
tb.moren1();
}
}
interface A1{
default void moren1(){
System.out.println("A1.moren1");
}
default void moren2(){
System.out.println("A1.moren2");
}
static void staticMethod(){
System.out.println("A1.静态方法");
}
}
class TestA implements A1{
@Override
public void moren1() {
System.out.println("TestA.moren1");
}
@Override
public void moren2() {
System.out.println("TestA.moren1");
}
static void staticMethod(){
System.out.println("实现类TestA.静态方法");
}
}
interface B1{
default void moren1(){
System.out.println("B1.moren1");
}
}
class TestB implements A1,B1{
@Override
public void moren1() {
System.out.println("TestB.moren1");
}
}