java-interface demo
2013-09-18 14:22
309 查看
1、主板demo
interface PCI
{
abstract void open();
abstract void close();
}
class MainBoard
{
void usePCI(PCI p)
{
p.open();
p.close();
}
}
class netCard implements PCI
{
public void open()
{
System.out.println("netCard
open!");
}
public void close()
{
System.out.println("netCard
close!");
}
}
class soundCard implements PCI
{
public void open()
{
System.out.println("soundCard
open!");
}
public void close()
{
System.out.println("soundCard
close!");
}
}
class MainBoardDemo
{
public static void main(String[] args)
{
final int x = 0;
class Test
{
void
get()
{
System.out.println("soundCard
close!" + x);
}
}
Test t = new Test();
t.get();
MainBoard mb = new
MainBoard();
mb.usePCI(new
netCard());
mb.usePCI(new
soundCard());
}
}
2、人demo
class InterfaceDemo
{
public static void main(String[] args)
{
Person p = new Student();
Student s = (Student) p;
s.say();
s.chifan();
s.shuijiao();
//System.out.println("Hello
World!");
}
}
class Person
{
void shuijiao()
{
System.out.println("睡觉");
};
}
class Student extends Person implements Smoke,Chifan
{
public void say()
{
System.out.println("Hello!");
}
public
void chifan()
{
System.out.println("chifan!");
}
}
interface Smoke
{
public abstract void say();
}
interface Chifan
{
void chifan();
}
interface PCI
{
abstract void open();
abstract void close();
}
class MainBoard
{
void usePCI(PCI p)
{
p.open();
p.close();
}
}
class netCard implements PCI
{
public void open()
{
System.out.println("netCard
open!");
}
public void close()
{
System.out.println("netCard
close!");
}
}
class soundCard implements PCI
{
public void open()
{
System.out.println("soundCard
open!");
}
public void close()
{
System.out.println("soundCard
close!");
}
}
class MainBoardDemo
{
public static void main(String[] args)
{
final int x = 0;
class Test
{
void
get()
{
System.out.println("soundCard
close!" + x);
}
}
Test t = new Test();
t.get();
MainBoard mb = new
MainBoard();
mb.usePCI(new
netCard());
mb.usePCI(new
soundCard());
}
}
2、人demo
class InterfaceDemo
{
public static void main(String[] args)
{
Person p = new Student();
Student s = (Student) p;
s.say();
s.chifan();
s.shuijiao();
//System.out.println("Hello
World!");
}
}
class Person
{
void shuijiao()
{
System.out.println("睡觉");
};
}
class Student extends Person implements Smoke,Chifan
{
public void say()
{
System.out.println("Hello!");
}
public
void chifan()
{
System.out.println("chifan!");
}
}
interface Smoke
{
public abstract void say();
}
interface Chifan
{
void chifan();
}
相关文章推荐
- interface & implementation demo in Java
- java for语句demo
- Java 多线程 死锁Demo
- 报错:Caused by: java.lang.Illeg…
- 黑马程序员java JText的数据添加到…
- java 随机码
- ALV demo:cl_salv_table&nbs…
- java JDBC实验题【实验题2 学生信…
- Java SE 环境安装和配置
- java自己造 编程IDE【2】,消…
- java基础入门之Hibernate 入门
- 《thinking in java》学习笔记18
- java split
- java RSA加密解密
- java 生成pdf文件 注解…
- javaEE servlet-01
- Ubuntu16.04安装ptotobuf&Java Demo
- java 温习之字符串(统计字串…
- Java FileWriter中文乱码
- java中的LinkedList 和 …