文章会有【原创】或者【转载】标示,部分来自Google Baidu的学习结果 {Java/PHP/Python/Ruby/Go}

Java 在学习三十三【原创】  


1】一个类可以继承多个接口;

2Java中是单一继承,但是接口与接口之间可以是多继承;


package coreJava;


public class Test9 {


public static void main(String[] args) {

// TODO Auto-generated method stub

Hero h = new Hero();

h.getFly();

h.getRead();

h.walk();

}


}


abstract class PersonA {

public abstract void walk();

}


interface C11 {

public abstract void getFly();

}


interface C22 {

public abstract void getRead();

}


class Hero extends PersonA implements C11, C22 {


@Override

public void getRead() {

// TODO Auto-generated method stub

System.out.println("Read...");

}


@Override

public void getFly() {

// TODO Auto-generated method stub

System.out.println("Fly...");

}


@Override

public void walk() {

// TODO Auto-generated method stub

System.out.println("Walk...");

}

}


Serializable 接口继承没有任何实现的方法,只是一个标准】

【接口中可以声明变量,即使没有这样写,默认是也是public static final


package coreJava;


import java.io.Serializable;


public class Test10 {


public static void main(String[] args) {

// TODO Auto-generated method stub

MyTest t = new MyTest();

t.C33();

t.getFly();

t.getRead();

System.out.println(t.a);

}


}


interface MyInterface extends C11, C22, Serializable, Cloneable {

public static final String a = "test";

public abstract void C33();

}


class MyTest implements MyInterface {


@Override

public void getFly() {

// TODO Auto-generated method stub

System.out.println("getFly..." + a);

}


@Override

public void getRead() {

// TODO Auto-generated method stub

System.out.println("getRead...");

}


@Override

public void C33() {

// TODO Auto-generated method stub

System.out.println("c33...");

}

}


【接口定义的方法很多,我只用一个方法怎么办,这里就有叫适配器的例子】

package coreJava;


public class Test11 {


public static void main(String[] args) {

// TODO Auto-generated method stub

A2 a2 = new A2();

a2.c();

}


}


interface T {

void a();

void b();

void c();

void d();

void e();

}


class A1 implements T {


@Override

public void a() {

System.out.println("a....");

}


//只要有花括号就是表示实现了方法

@Override

public void b() {

}


@Override

public void c() {

}


@Override

public void d() {

}


@Override

public void e() {

}

}


//适配器类

abstract class TTAdapter implements T {

@Override

public void a() {}


@Override

public void b() {}


@Override

public void c() {}


@Override

public void d() {}


@Override

public void e() {}

}


class A2 extends TTAdapter {

public void c() {

System.out.println("c....");

}

}