1 / 10

Inheritance – Subclasses and Superclasses

Inheritance – Subclasses and Superclasses. Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com May 2, 2013. Agenda. Announcements – CS Seminar this Friday, May 3, 1-2pm, ground floor CCSB Assess Programming Exercises 8.1, 8.8 Inheritance Assignments for next class.

masao
Download Presentation

Inheritance – Subclasses and Superclasses

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Inheritance – Subclasses and Superclasses Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com May 2, 2013

  2. Agenda • Announcements – CS Seminar this Friday, May 3, 1-2pm, ground floor CCSB • Assess Programming Exercises 8.1, 8.8 • Inheritance • Assignments for next class

  3. Programming Exercise 8.1 – Rectangle class and test program • Design a class named Rectangle. The class should contain: • Two double fields named width and height. The default values are 1 for both. • A no-arg constructor that creates a default rectangle. • A constructor that creates a rectangle with the specified width and height. • A getArea() method that returns the area of this rectangle. • A getPerimeter() method that returns the perimeter. • Draw the UML diagram and implement the class. Write a test program that creates two Rectangle objectts – one with width 4 and height 40 and one with width 3.5 and height 35.9. Display the width, height, area, and perimeter of each rectangle.

  4. Programming Exercise 8.8 – Fan class and test program

  5. Inheritance • Allows you to define new classes from existing classes and reuse data fields and methods • Superclass is general class • Subclasses are specializations • Example • Superclass: Geometric Object • Subclasses: Circle and Rectangle

  6. Class Activity • Download files from class website: • GeometricObject.java • Circle2.java • Rectangle2.java • Discuss • “extends” keyword • constructor chaining • Overloading vs. overriding • Test with examples in Dr. Java Interactions pane

  7. Assignments for Next Class • Quiz 7 (Take-home) • Read Sections 11.1-11.5 • Programming Exercises 11.1, 11.2

More Related