You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.3 KiB

public class Jb31_ObjPol
{
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD>̬<EFBFBD><CCAC>;<3B><><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD>־<EFBFBD><D6BE>Ǹ<EFBFBD><C7B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿڵ<D3BF><DAB5><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>
public static void main(String[] args)
{
/*<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>)<EFBFBD><EFBFBD>è<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><EFBFBD><EFBFBD><EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><EFBFBD>ܵķ<EFBFBD><EFBFBD><EFBFBD>*/
Animal a = new Cat();
a.eat();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫʹ<D2AA><CAB9>è<EFBFBD><C3A8><EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD><C3B9>ܣ<EFBFBD><DCA3>ɽ<EFBFBD><C9BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
//<2F><>ʼ<EFBFBD><CABC><EFBFBD>ն<EFBFBD><D5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵ı
Cat c = (Cat)a; //<2F><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><C3B7><EFBFBD>
c.eat();
c.catch();
/*
Cat c = new Cat();
//Dog d = new Dog();
//c.eat();
method(c);
method(new Dog());
*/
method(new Cat());
}
/*<EFBFBD><EFBFBD>̬<EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>ԣ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ú<EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD>׶ˣ<EFBFBD>ǰ<EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ʹ<EFBFBD>ö<EFBFBD>̬ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD>̳С<EFBFBD>ʵ<EFBFBD><EFBFBD>
Ҫ<EFBFBD>з<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
public static void method(Animal a)
{
a.eat();
if (a instanceof Cat)
//instanceof <20><><EFBFBD><EFBFBD><EFBFBD>ж϶<D0B6><CFB6><EFBFBD><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
//ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>ǰ<EFBFBD><C7B0><EFBFBD>ڽ<EFBFBD>׳<EFBFBD>Ե<EFBFBD><D4B5>ж<EFBFBD>
{
Cat c2 = (Cat)a;
c2.catch();
}
else if (a instanceof Dog)
{
Dog d2 = (Dog)a;
d2.watchHome();
}
}
}
abstract class Animal
{
abstract void eat();
}
class Dog extends Animal
{
public void eat()
{
System.out.println("<22><>ʺ");
}
public void watchHome()
{
System.out.println("<22><><EFBFBD><EFBFBD>");
}
}
class Cat extends Animal
{
public void eat()
{
System.out.println("<22><><EFBFBD><EFBFBD>");
}
public void catch()
{
System.out.println(<><D7BD><EFBFBD><EFBFBD>");
}
}