接口的简单应用
来源:互联网 发布:网络渗透软件 编辑:程序博客网 时间:2024/05/01 14:38
interface Singer{
public void sing();
public void sleep();
}
interface Panit{
public void paint();
public void eat();
}
class Student implements Singer{
String name;
public Student(String name){
this.name=name;
}
public void sing(){
System.out.println(this.name+"==========Student is singing========");
}
public void sleep(){
System.out.println(this.name+"==========Student is sleep===========");
}
//Student自己的方法
public void study(){
System.out.println(this.name+"==========student is Studying==========");
}
}
class Teacher implements Singer,Panit{
String name;
public Teacher(String name){
this.name=name;
}
public void sing(){
System.out.println(this.name+"==========Teacher is singing========");
}
public void sleep(){
System.out.println(this.name+"==========Teacher is sleep===========");
}
public void paint(){
System.out.println(this.name+"==========Teacher is painting========");
}
public void eat(){
System.out.println(this.name+"==========Teacher is eating===========");
}
//Teacher自己的方法
public void teach(){
System.out.println(this.name+"==========Teacher is Teaching==========");
}
}
public class A{
public static void main (String [] args)
{
Singer s1=new Student("马建杰");
Singer s2=new Teacher("王伟");
s1.sing();
s2.sing();
//s2.eat(); //找不到eat方法,因为在s2 看来,s2是Singer身份,他无法使用 teacher自己的方法和panit 的方法
//s2.teach(); //同上。。。
Panit p=(Panit)s2;
p.eat();
System.out.println("*********************************************");
f(s1);
f(s2);
}
public static void f(Singer s){
s.sing();
}
}
public void sing();
public void sleep();
}
interface Panit{
public void paint();
public void eat();
}
class Student implements Singer{
String name;
public Student(String name){
this.name=name;
}
public void sing(){
System.out.println(this.name+"==========Student is singing========");
}
public void sleep(){
System.out.println(this.name+"==========Student is sleep===========");
}
//Student自己的方法
public void study(){
System.out.println(this.name+"==========student is Studying==========");
}
}
class Teacher implements Singer,Panit{
String name;
public Teacher(String name){
this.name=name;
}
public void sing(){
System.out.println(this.name+"==========Teacher is singing========");
}
public void sleep(){
System.out.println(this.name+"==========Teacher is sleep===========");
}
public void paint(){
System.out.println(this.name+"==========Teacher is painting========");
}
public void eat(){
System.out.println(this.name+"==========Teacher is eating===========");
}
//Teacher自己的方法
public void teach(){
System.out.println(this.name+"==========Teacher is Teaching==========");
}
}
public class A{
public static void main (String [] args)
{
Singer s1=new Student("马建杰");
Singer s2=new Teacher("王伟");
s1.sing();
s2.sing();
//s2.eat(); //找不到eat方法,因为在s2 看来,s2是Singer身份,他无法使用 teacher自己的方法和panit 的方法
//s2.teach(); //同上。。。
Panit p=(Panit)s2;
p.eat();
System.out.println("*********************************************");
f(s1);
f(s2);
}
public static void f(Singer s){
s.sing();
}
}
0 0
- 接口的简单应用
- interface ---接口 的简单应用
- .net 简单的接口应用
- Java Interface接口的简单应用
- 委托和接口的简单应用
- 对WindowListener接口的简单应用
- 比较器的简单应用(Comparable接口)
- 简单接口和继承的应用
- C# 接口的特点、接口的作用、接口的简单应用
- JAVA接口的应用及工厂模式的简单示例
- servlet 的接口的基本应用和filter简单实现
- 使用Delphi调用WebServices接口的简单应用实例
- 使用Delphi调用WebServices接口的简单应用实例
- IDirect3DDevices9接口怎样应用到简单的二维应用程序里
- python学习:最简单的web应用(WSGI接口)
- 使用webservice调用天气接口的简单应用
- 接口的应用
- 接口测试的应用
- const int function(const int a,const int b) const的意义
- 冬季热车的注意事项
- 解决隐式声明与内建函数不兼容问题
- 重写Equals方法
- 动态绑定(多态)
- 接口的简单应用
- 黑马程序员_JAVA学习笔记12
- SqlParameter[]写法
- 增强版for循环
- 重写hashCode方法
- ASP.NET MVC4+ORACLE+EF+EXTJS4.2.1开发
- android跨进程通信(IPC):使用AIDL
- 遍历磁盘
- 记得常回头看看以前犯的错误,但绝不要为它们感到后悔