码迷,mamicode.com
首页 > 其他好文 > 详细

接口2

时间:2018-12-27 11:59:32      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:abstract   sys   name   table   pre   inter   void   int   imp   

例子:

 

public interface Valuable {
	public double getMoney();
}

interface Protectable {
	public void beProtected();
}

interface A extends Protectable {
	void m();
	//void getMoney();
}

abstract class Animal {
	private String name;
	
	abstract void enjoy();
}

class GoldenMonkey extends Animal implements Valuable, Protectable {
	public double getMoney() {
		return 10000;
	}
	
	public void beProtected() {
		System.out.println("live in the room");
	}
	
	public void enjoy() {
		
	}
	
	public void test() {
		Valuable v = new GoldenMonkey();
		v.getMoney();
		Protectable p = (Protectable)v;
		p.beProtected();
	}
}

class Hen implements A  {
	public void m() {}
	public void beProtected() {}
	//public double getMoney() {
	//	return 1.0;
	//}
	
	//public void getMoney() {}

}

  

接口2

标签:abstract   sys   name   table   pre   inter   void   int   imp   

原文地址:https://www.cnblogs.com/white-the-Alan/p/10184025.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!