正在加载图片...
Overloading constructors r As we can overload regular methods we can overload constructors a class with multiple constructors allows the programmer a flexibility in creating instances. This improves the usability of the class public Drawing Board( this(DRAWING board")i This calls the other constructor public DrawingBoard( string title setTitle( title setResizable( false setBackground( Color. white )i C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12-7© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12 - 7 Overloading Constructors As we can overload regular methods, we can overload constructors. A class with multiple constructors allows the programmer a flexibility in creating instances. This improves the usability of the class. public DrawingBoard( ) { this( “DRAWING BOARD”); } public DrawingBoard( String title ) { setTitle( title ); setResizable( false ); setBackground( Color.white ); } This calls the other constructor
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有