本帖最后由 陈延真 于 2013-5-30 21:30 编辑
public class Test1
{
public static void main(String[] args)
{
Animal a = new Dog("ok dog");
a.show();
// a.setName("ok dog");
a.getName();
/*Dog d = new Dog();
System.out.println(d.getName());
Dog d2 = new Dog("ok dog");
System.out.println(d2.getName());
d2.show();
d2.method();*/
}
}
abstract class Animal
{
private String name;
public final int x = 10;
public Animal()
{
System.out.println("Animal");
}
public Animal(String name)
{
this.name = name;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void show()
{
System.out.println("show");
}
public abstract void method();
}
class Dog extends Animal
{
public Dog()
{
super();
System.out.println("dog");
}
public Dog(String name)
{
super(name);
}
public void show()
{
System.out.println("show");
}
public void method()
{
System.out.println("dog method");
}
} |