正在加载图片...
Using polymorphism Effectively r Polymorphism is a feature that allows the rogrammer to send the same message to objects om diffe erent classes r Polymorphism allows the same variable to refer to objects from different(but related) classes Student studenti This will call the student new Graduatestudent()i method of Graduate student student. computeCourseGrade( )i Student student This will call the student new UndergraduateStudent()i method of Undergraduate Student student. compute CourseGrade( )i C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 14-5© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 14 - 5 Using Polymorphism Effectively Polymorphism is a feature that allows the programmer to send the same message to objects from different classes. Polymorphism allows the same variable to refer to objects from different (but related) classes. Student student; student = new GraduateStudent(); student.computeCourseGrade( ); Student student; student = new UndergraduateStudent(); student.computeCourseGrade( ); This will call the method of GraduateStudent This will call the method of UndergraduateStudent
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有