javah接口

接口是java中最重要的概念,接口可以理解为一种特俗的类,里面全部是由全局常量和公共的抽象方法所组成

package come.liuchen.javaextends;
interface Inter{
	public static final int AGE=100;
	public abstract void tell();
}

public class demo4 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
	}

}

接口的格式:

interface interfaceName{

全局常量

抽象方法

}

接口的实现也可以通过子类,使用关键字implements,而且接口是可以多实现的


接口不能直接实例化!通过子类在实例化

package come.liuchen.javaextends;
interface Inter1{
	public static final int AGE=100;
	public abstract void tell();
}
class A implements Inter1{
	public void tell() {
		
	}
}
public class demo4 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		A a=new A();
		a.tell();
		System.out.println(Inter1.AGE);
	}

}
一个类可以继承多个接口!

package come.liuchen.javaextends;
interface Inter1{
	public static final int AGE=100;
	public abstract void tell();
}
class A implements Inter1{
	public void tell() {
		
	}
}
public class demo4 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		A a=new A();
		a.tell();
		System.out.println(Inter1.AGE);
	}

}
子类可以同时继承抽象类,接口

package come.liuchen.javaextends;
interface Inter1{
	public static final int AGE=100;
	public abstract void tell();
}
interface Inter2{
	public abstract void say();
}
abstract class Abs1{
	public	abstract void  print();
}
class A extends Abs1 implements Inter1,Inter2{
	public void tell() {
		
	}
	public void say() {
		
	}
	public void print() {
		
	}
}
public class demo4 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		A a=new A();
		a.tell();
		System.out.println(Inter1.AGE);
		a.say();
	}

}

一个接口可以同时继承多个接口(弥补了一个类不能同时继承多个类的不足)


package come.liuchen.javaextends;
interface Inter1{
	public static final int AGE=100;
	public abstract void tell();
}
interface Inter2{
	public abstract void say();
}
abstract class Abs1{
	public	abstract void  print();
}
class A extends Abs1 implements Inter1,Inter2{
	public void tell() {
		
	}
	public void say() {
		
	}
	public void print() {
		
	}
}
interface Inter3 extends Inter1,Inter2{
	
}
public class demo4 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		A a=new A();
		a.tell();
		System.out.println(Inter1.AGE);
		a.say();
		System.out.println(Inter3.AGE);
	}

}






































































评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值