public void sayHello()
{
System.out.println("Hello");
}
public abstract void say();
}
class Worker extends Person
{
public void say()
{
System.out.println("我是worker");
}
}
class Studentt extends Person
{
public void say()
{
System.out.println("我是Student");
}
}
class Testt
{
public static void say(Person p)
{
p.sayHello();
p.say();
}
public static void main(String[] p)
{
new Testt().say(new Worker());
new Testt().say(new Studentt());
}
}
/**
*
*/
/**
* @author Leslie
*
*/
abstract class TestA {
public abstract void doSomething();
}
class TestB extends TestA {
public void doSomething() {
System.out.println("do B");
}
}
class TestC extends TestA {
public void doSomething() {
System.out.println("do C");
}
}
public class Test {
public static void main(String[] args) {
TestA a1 = new TestB();
TestA a2 = new TestC();
TestB b = new TestB();
TestC c = new TestC();
doSome(a1);
doSome(a2);
doSome(b);
doSome(c);
}
public static void doSome(TestA a) {//这里,用到抽象类
System.out.println("what is this~");
a.doSomething();
}
}