next up previous contents index
Next: Component declarations Up: ClassesComponents, and Previous: Writing classes

Using inheritance

DJ retains the object-oriented feature of Java. A class A can extends another class B. In this case, class A is called a subclass of B, and class B is called the super class of A. By using inheritance, we can write the HelloWorldButton as follows:

       class HelloWorldButton extends Button {
             text=="Hello World!";
       }
Although the two HelloWorldButton classes specify the same sub-panel, their definitions are different. For the previous definition, for example, we reference the size of the button as hw.bt.size. For this declaration, however, we reference the size of the button as hw.size. The attribute size in HelloWorldButton is inherited from its super class Button.  



Neng-Fa ZHOU
Sat Apr 18 16:14:29 JST 1998