Inheritance in Java

xiaoxiao2021-03-11  187

Perhaps the most powerful tool in the object-oriented program is the inheritance of the class, the inheritance of the class allows you to write new programs on a existing class, for example, you want to create a screen to display and populate it on the screen. The rectangular class, you can start from the beginning or with the old rectangular class, the following section will introduce you how to inherit the existing Rectangle class without rewriting the code. Using the extages keyword allows the Java programmer to inherit the members of the existing class, in order to tell the compiler and interpreter you are inheriting the Rectangle class, you must reference the old Rectangle class, and reference it in the new class: import shapes This is. Rectangle; Class FillRect ExtAnds Rectangle // New Code Here This FillRect class will be able to use all defined data and member functions in the Rectangle class, such as: Width, Height and other member functions.

转载请注明原文地址:https://www.9cbs.com/read-128965.html

New Post(0)