如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
面向对象编程的高级概念2005IBMSoftwareInstituteIBMSoftwareInstitute主要内容类的继承抽象类和接口Java语言的包内部类与嵌套类课程大标题2005IBMSoftwareInstituteIBMSoftwareInstitute类的继承——继承的实现classEmployee{继承使得子类可以利Stringname;用父类中定义的方法和变量,就像它们属publicvoidshowName(){System.out.println(name);于子类本身一样。}}classManagerextendsEmployee{Stringdepartment;publicvoidshowInfo(){showName();System.out.println(“Managerof”+department);}}课程大标题2005IBMSoftwareInstituteIBMSoftwareInstitute类的继承——域的隐藏classEmployee{子类重新定义一个与Stringname;从父类那里继承来的Stringdepartment;域变量完全相同的变publicvoidshowName(){System.out.println(name);量成为域的隐藏}}classManagerextendsEmployee{Stringdepartment;publicvoidshowInfo(){showName();System.out.println(“Managerof”+department);}}课程大标题2005IBMSoftwareInstituteIBMSoftwareInstitute类的继承——方法的覆盖classEmployee{覆盖使得在子类中可Stringname;以重新定义父类中已有的方法,从而使子publicvoidshowInfo(){System.out.println(name);类具有自己的行为。}}classManagerextendsEmployee{Stringdepartment;publicvoidshowInfo(){System.out.println(name);System.out.println(“Managerof”+department);}}课程大标题2005IBMSoftwareInstituteIBMSoftwareInstitute类的继承——this与superclassCircle{this和super是用来指代父doubler;类和子类的对象的关键字。Circle(intr){this:代表了当前对象的一this.r=r;个引用}publicdoublearea(){super:是当前对象的直接returnr*r*3.14;父类对象的引用}二者还可以调用当前对象或}父类对象的构造函数classappleextendsfruits{publicapple(intprice){super(price);super.var=someValue;super.method(someParaList);}}课程大标题2005IBMSoftwareInstituteIBMSoftwareInstitute类的继承——继承、隐藏和覆盖示例publicclassMySubClassextendsMyClass{publicStrings="amemberofMySubClass";publicvoidtest(){super.test();System.out.println(s);}publicstaticvoidmain(String[]args){MySubClassmsc=newMySubClass();System.out.println(msc.s);amemberofMySubClassmsc.test();amemberofMyClass}amemberofMySubClass}classMyClass{protectedStrings="amemberofMyClass";protectedvoidtest(){System.out.println(s);}}课程大标题2005IBMSoftwareInstituteIBMSoftwareInstitute类的继承——父子类对象转换原则classSuperClas