CIS234 Chapter07

CIS234 Chapter07 - Inheritance Chapter VII 1 Professor...

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

View Full Document Right Arrow Icon
heritance Inheritance Chapter VII Professor Hatim Mouissa CIS 234 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
New concepts and keywords ± Inheritance bclasses and Superclasses ± Subclasses and Superclasses ± Overriding Methods ± Polymorphism ± Abstract Classes Professor Hatim Mouissa CIS 234 2
Background image of page 2
Inheritance Introduction ± Software reuse is at the heart of inheritance ± By using existing software components to create new nes we capitalize on all the effort that went into the ones, we capitalize on all the effort that went into the design, implementation , and testing of the existing software heritance allows a software developer to derive a new ± Inheritance allows a software developer to derive a new class from an existing one ± The existing class is called the parent class, or perclass or aseclass superclass , or baseclass ± The derived class is called the child class or subclass . Person name age Student gpa broncoID Professor Hatim Mouissa CIS 234 3 drink() sleep() eat() takeExam() study() graduate()
Background image of page 3

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

View Full DocumentRight Arrow Icon
Inheritance ± As the name implies, the child inherits characteristics of the parent ± The child class inherits the behaviors (methods) and attributes (properties) defined for the parent class ± To enhance the derived class, the programmer can add new variables or methods ± Methods in the parent class can be modified this is referred to as overriding methods. tudent tudent Student name age gpa roncoID Student name age gpa roncoID Override Method broncoID drink() sleep() eat() broncoID drink() sleep() eat() sleep() Î 4 takeExam() study() graduate() takeExam() study() graduate()
Background image of page 4
Inheritance Examples Employee Bank Account xamples Examples Of Subclasses? Hourly Employee Salary Employee Savings Checking Employee is a general employee class. Stores information such as name, social security number, phone number, address, etc. Bank Account is a general bank account class common to all bank accounts Savings is a subclass of bank account and HourlyEmployee is a specialized class for employees who are paid by the hour. An HourlyEmployee object stores hours and rate data. SalaryEmployee is a specialized class for employees defines accounts that can earn interest Checking is also a subclass of bank account that allows for check writing privileges Professor Hatim Mouissa CIS 234 5 who are paid a monthly salary. A SalaryEmployee object stores annual salary data.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Inheritance ± Inheritance relationships often are shown graphically in a UML class diagram, with an arrow with an open arrowhead pointing to the parent class Bank Acct Saving Acct Checking Acct Timed Acct Inheritance should create an is-a relationship , meaning the child is a more specific version Professor Hatim Mouissa CIS 234 6 of the parent
Background image of page 6
Creating subclasses / Java Syntax ± In Java, we use the reserved word extends to establish an inheritance relationship class Car extends Vehicle { // class contents } ± Visibility modifiers determine which class members can be used by derived classes and which cannot
Background image of page 7

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

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

Page1 / 23

CIS234 Chapter07 - Inheritance Chapter VII 1 Professor...

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

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