正在加载图片...
Method Overriding r Two techniques to make a class more reusable are method overriding and method overloading r We say a method of a subclass overrides the inherited method when we redefine the method in the subclass Example: setvisible of drawing board overrides setvisible of MainWindow public class DrawingBoard extends MainWindow public void setvisible( boolean state The reserved word super setVisible( state )i super refers to the graphic= getGr aphics()i superclass } C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12-5© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12 - 5 Method Overriding Two techniques to make a class more reusable are method overriding and method overloading. We say a method of a subclass overrides the inherited method when we redefine the method in the subclass. Example: setVisible of DrawingBoard overrides setVisible of MainWindow public class DrawingBoard extends MainWindow { . . . public void setVisible( boolean state ) { super.setVisible( state ); graphic = getGraphics( ); } . . . } The reserved word super refers to the superclass
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有