J2EEOnline J2EEOnline


Java Basics  «Prev

Java Classes you might extend

List the four classes that you are most likely to extend

Identify when to extend object, applet, thread, and panel:
Java's classes will be used as your base classes. That is, at some point in a class hierarchy, your own classes will extend one of Java's predefined classes, available from one of Java's class libraries. Four classes that you are likely to extend most often.
  1. Extend Object when you only want the basic behavior for a class, that is, the ability to create new objects using new, and the ability to find out some basic attributes of an object, such as which class it belongs to.
    If you want to extend class Object, you do not need to do so explicitly, because Java extends class Object.
    In fact, the preferred way to extend class Object for a new class called MyClass is to simply write:
    class MyClass {
    // your class definition...
    }
    
  2. Extend Applet when you create your own applet to run within a Web browser.
  3. Extend Thread to implement another thread of execution. You will learn in the advanced class how to provide the behavior for your new thread so that it performs its own special behavior.
  4. Extend Panel to organize your user interface. Panels help group and display other user interface components, such as buttons, check boxes, and so on. Panels will be discussed in the class on graphical user interfaces.