如题,现在已经在边复习边写博客的阶段了,正好到抽象类接口多态这部分,刚自己写了个例子。有兴趣的看看~高手绕行啦~
public class Interface {
public static void main(String[] args)
{
// Lumiaphone1 lp=new Lumiaphone1("lumia930",5.0,"骚黄");
// lp.function();
// lp.speak();
// lp.zhuangbi();
// Lumiaphone1 lp2=new Lumiaphone2("lumia930",5.0,"骚黄");
phone1 p=new Lumiaphone1("lumia625",5.0,"骚黄");
p.function();
}
public static void superfunction(phone1 p)
{
}
}
interface inter1
{
void zhuangbi();
}
abstract class phone1 implements inter1
{
private String name;
private double chicun;
private String color;
phone1(String name,double chicun,String color)
{
this.name=name;
this.chicun=chicun;
this.color=color;
}
void speak()
{
System.out.println("通话");
System.out.println("name:"+name+" chicun:"+chicun+" color"+color);
}
abstract void function();
public void zhuangbi()
{
System.out.println("Fuck!就是那么自信!");
}
}
class Lumiaphone1 extends phone1
{
Lumiaphone1(String name,double chicun,String color)
{
super(name,chicun,color);
}
void function()
{
System.out.println("带你装逼带你飞");
}
}
class Lumiaphone2 extends Lumiaphone1
{
Lumiaphone2(String name,double chicun,String color)
{
super(name,chicun,color);
}
void paizhao()
{
System.out.println("4100W像素~");
}
} |
|