标签:
class Pencil
{
String name;
Pencil(){}
Pencil(String name)
{
this.name = name;
}
public void write()
{
System.out.println("write quickly...");
}
}
interface Eraser
{
public static final String color = "白色";
public abstract void clean();
}
//()
class PencilWithEraser extends Pencil implements Eraser
{
PencilWithEraser(){}
PencilWithEraser(String name)
{
super(name);
}
//public
public void write()
{
System.out.println("super "+ super.name+ "PencilWithEraser‘s name...");
System.out.println("this "+ this.name+ "PencilWithEraser‘s name...");
}
//void clean()
public void clean()
{
System.out.println("ERROR, use Eraser...");
}
}
public class jiekou
{
public static void main(String[] args)
{
PencilWithEraser p = new PencilWithEraser("中华");
p.write();
p.clean();
System.out.println(p.color);
System.out.println(PencilWithEraser.color);
}
}
运行结果:
super 中华PencilWithEraser‘s name...
this 中华PencilWithEraser‘s name...
ERROR, use Eraser...
白色
白色
标签:
原文地址:http://www.cnblogs.com/Ant-/p/5958155.html