复制代码
- //:HorrorFlick.java
- //YoucaninsertCloneabilityatany
- //levelofinheritance.
- importjava.util.*;
- classPerson{}
- classHeroextendsPerson{}
- classScientistextendsPerson
- implementsCloneable{
- publicObjectclone(){
- try{
- returnsuper.clone();
- }catch(CloneNotSupportedExceptione){
- //thisshouldneverhappen:
- //ItsCloneablealready!
- thrownewInternalError();
- }
- }
- }
- classMadScientistextendsScientist{}
- publicclassHorrorFlick{
- publicstaticvoidmain(String[]args){
- Personp=newPerson();
- Heroh=newHero();
- Scientists=newScientist();
- MadScientistm=newMadScientist();
- //p=(Person)p.clone();//Compileerror
- //h=(Hero)h.clone();//Compileerror
- s=(Scientist)s.clone();
- m=(MadScientist)m.clone();
- }
- }///:~
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |