{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

define methods

define methods - The subclass definition The manila folder...

Info icon This 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
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern