Define methods - The subclass definition The manila folder for subclass Demo Here is a manilla folder-an object or instance of class JFrame The tab

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
The subclass definition The manila folder for subclass Demo Here is a manilla folder —an object or instance— of class JFrame . The tab contains the name of the folder, the name of the class appear in the upper right, and we show only some of the methods and none of the fields in the folder. The definition of class Demo extends JFrame . We say that Demo is a subclass of JFrame and JFrame is the superclass of Demo . Remember these terms. We draw a folder of class Demo with two partitions. The top partition is labeled JFrame ; it contains all the components —fields and methods— that a JFrame has. We say that Demo inherits all these components. The bottom partition is for components that are defined in Demo itself. There are none yet. The Demo partition appears below the JFrame partition because Demo is a subclass of JFrame . Defining a function Let’s define a function in class Demo that yields the area of the window in pixels —its height times its width. This is your first Java function definition. We start off with its specification, as a comment. It says that a call of this function equals the area of the window. Now we put the header of the function. Keyword public means that it can be called from any part of the program; the function will return an integer, an
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/07/2008 for the course CS 101 taught by Professor Gries during the Spring '08 term at Cornell University (Engineering School).

Page1 / 2

Define methods - The subclass definition The manila folder for subclass Demo Here is a manilla folder-an object or instance of class JFrame The tab

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online