10-1 Intro Inheritance1 of 4 Inheritance is a mechanism for enhancing existing classes. Inheritance is a mechanism for enhancing existing classes. A new.

Slides:



Advertisements
Similar presentations
Chapter 13 - Inheritance. Goals To learn about inheritance To learn about inheritance To understand how to inherit and override superclass methods To.
Advertisements

CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Inheritance Part I. Lecture Objectives To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass.
I NHERITANCE Chapter 10. I NHERITANCE Mechanism for enhancing existing classes You need to implement a new class You have an existing class that represents.
1 CS 171: Introduction to Computer Science II Review: OO, Inheritance, and Libraries Ymir Vigfusson.
Object-Oriented Programming Part 2 Bank Account Exercise Hood College JETT Workshop Dept. of Computer Science February
Inheritance. Class Relationships Composition: A class contains objects of other class(es) (actually, references to such objects) –A “has a” relationship.
Chapter 13 Inheritance. An Introduction to Inheritance Inheritance: extend classes by adding methods and fields (variables) Example: Savings account =
“The task of leadership is not to put greatness into people, but to elicit it, for the greatness is there already.” – John Buchan Thought for the Day.
CHAPTER 11 INHERITANCE CHAPTER GOALS To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn.
Chapter 9 – Inheritance Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
Class Hierarchies, Inheritance and Interfaces CIS 304 Intermediate Java Programming for Business.
Inheritance Part III. Lecture Objectives To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
Object Oriented Design CSC 171 FALL 2001 LECTURE 12.
CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
CS 106 Introduction to Computer Science I 04 / 21 / 2010 Instructor: Michael Eckmann.
Inheritance Part II. Lecture Objectives To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass.
Checking Accounts. Things Not To Do Don’t write checks for more money than you have in your account. ▫You could be charged an overdraft fee by your financial.
Inheritance and Subclasses in Java CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University.
Checking Accounts & Other Banking Services Business Department Mrs. Pollison.
CHAPTER 10 OBJECT INHERITANCE Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
Inheritance One of the biggest advantages of object-oriented design is that of inheritance. A class may be derived from another class, the base class.
Chapter © 2010 South-Western, Cengage Learning Checking Accounts and Banking Services Banking Services and Fees 9.
(c) University of Washington04-1 CSC 143 Java Inheritance Example (Review)
CS 100Lecture 241 CS100J Lecture 24 n Previous Lecture –MatLab demonstration n This Lecture –Inheritance –Method overriding –Polymorphism –Reading: n Lewis.
Checking Accounts. What is a Checking Account? 1.A checking account is a sum of money that you deposit in a bank or other financial institution, to hold.
Programming Languages and Paradigms Object-Oriented Programming.
CS 106 Introduction to Computer Science I 04 / 13 / 2007 Friday the 13 th Instructor: Michael Eckmann.
Section 2Reconciling the Bank Account What You’ll Learn  Why a business reconciles a bank statement.  How to journalize and post entries relating to.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Inheritance.
Bank Accounts. Deposit Account: Deposit Account: An account at a banking institution which allows the account holder to deposit money into or withdraw.
Often categorize concepts into hierarchies: Inheritance Hierarchies Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
Inheritance in Java. RHS – SOC 2 What is inheritance (in Java)? Inheritance is a mechanism for enhancing existing classes What does that mean…? Defining.
 Sometimes a new class is a special case of the concept represented by another ◦ A SavingsAccount is-a BankAccount ◦ An Employee is-a Person  Can extend.
Inheritance CSC 171 FALL 2004 LECTURE 18. READING Read Horstmann, Chapter 11.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Bank Reconciliation Section 7.4. Reconciling your account Banks send statements monthly Banks send statements monthly Cancelled checks may accompany statement.
1 Inheritance Chapter 9. 2 What You Will Learn Software reusability (Recycling) Inheriting data members and functions from previously defined classes.
Topic 4 Inheritance.
CHAPTER 11 INHERITANCE. CHAPTER GOALS To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn.
Chapter Object Oriented Programming (OOP) CSC1310 Fall 2009.
A checking account is also called a “demand” deposit account because funds can be withdrawn, or “demanded” at any time by cashing a check. Check Writing.
Chapter 13 ATM Case Study Part 2: Implementing an Object-Oriented Design Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
Inheritance and Access Control CS 162 (Summer 2009)
Inheritance (Part 2) KomondorBloodHound PureBreedMix Dog Object.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
 Sometimes a new class is a special case of the concept represented by another ◦ A SavingsAccount is-a BankAccount ◦ An Employee is-a Person  Can extend.
(c) University of Washington06-1 CSC 143 Java Inheritance Tidbits.
CS1020 Lecture Note #7: Object Oriented Programming Inheritance Like father, like son.
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
Inheritance INHERITANCE: extend existing classes by adding or redefining methods, and adding instance fields Suppose we have a class Vehicle: public class.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 6 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
What are check OVERDRAFTS and how can this impact my account and other accounts? 1. Why should I maintain a check register? 3. How do I reconcile.
Do Now Why do people have checking accounts?. Unit 4: Lesson 13: Checking Accounts Day 1 Objective: identify vocabulary terms related to checking accounts.
Lesson 2: Introduction to Banking. Objectives: Identify types of accounts Evaluate banking transactions for accuracy and completeness Determine uses for.
Chapter 13 - Inheritance.
Data Structures and Algorithms revision
Inheritance In the real world, objects aren’t usually one-of-a-kind.
OBJECT ORIENTED PROGRAMMING II LECTURE 7 GEORGE KOUTSOGIANNAKIS
Lecture Notes – Inheritance (Ch 9-10)
Inheritance in Java.
Interfaces and Inheritance
CSC 205 Java Programming II
Checkbook Terminology
SECTION 4-4 Bank Statements pp
Presentation transcript:

10-1 Intro Inheritance1 of 4 Inheritance is a mechanism for enhancing existing classes. Inheritance is a mechanism for enhancing existing classes. A new more specific class that has all the traits of an existing class has the capability to inherit all the data & methodology from the more general class. A new more specific class that has all the traits of an existing class has the capability to inherit all the data & methodology from the more general class. Consider a “SavingsAcct” class which pays interest on the balance. We can have “SavingsAcct” inherit from the more general “BankAcct” class without having to reinvent the wheel(reuse). Consider a “SavingsAcct” class which pays interest on the balance. We can have “SavingsAcct” inherit from the more general “BankAcct” class without having to reinvent the wheel(reuse). public class SavingsAcct extends BankAcct public class SavingsAcct extends BankAcct{ // new methods, overloaded/overridden methods & instance fields } All methods & data of “BankAcct” are inherited by “SavingsAcct”. All methods & data of “BankAcct” are inherited by “SavingsAcct”.  Be aware of access privileges though! Consider: Consider:  SavingsAcct s = new SavingsAcct(3.5);  s.deposit(1000);// method from “BankAcct”!  s.deposit(1000);// method from “BankAcct”!

10-1 Intro Inheritance Cont.2 of 4 Terminology: Terminology:  Superclass – Base class or more general class (“BankAcct”);  Subclass – Class inheriting or more specific class(“SavingsAcct”). Every class in Java extends from the Object class. Every class in Java extends from the Object class.  The Object class is the lowest common denominator among all classes.  The object class has some common methods which all class objects have access to : .toString( ) .equals(Object obj)  The Programmer must override these methods for specific meaning!  Overriding Overloading?

10-1 Intro Inheritance Cont.3 of 4 In-Class Work: In-Class Work:  Write a subclass “SavingsAcct” extending “BankAcct” with:  Instance Field: myRate  Method:addInterest( )  Now write the client (tester) code to perform the following: 1. Create a new SavingsAcct reference. 3.25% 2. Deposit $ Calculate Interest 4. Deposit another $ Calculate Interest 6. Withdraw $ Calculate Interest 8. Print the Balance

Homework Homework I.Add another subclass CheckingAcct with the following attributes:  CheckingAcct extends BankAcct //data- myNumCks- incr whenever check is written. //myTransactions- incr whenever a transaction occurs. i.e. deposit( ), withdraw( ), …  writeCheck( ) Call validateFunds( )Call validateFunds( ) deduct amount from balancededuct amount from balance increment myNumCksincrement myNumCks  deductFees( ) Charge a $0.25 fee for every 10 th check written.Charge a $0.25 fee for every 10 th check written.  validateFunds( ) Verify there are enough funds to cover check.Verify there are enough funds to cover check. Charge a $5 fee if balance falls below $100.Charge a $5 fee if balance falls below $100. II.Write a transfer(BankAcct acct, double amt) method in BankAcct which transfers amt from the parameter BankAcct acct and deposits to the implicit parameter.