ACCTG 1 Lecture Notes - Lecture 4: Code Reuse, Multiple Inheritance

9 views13 pages
6 Sep 2020
School
Department
Course
Professor

Document Summary

One advantage of inheritance is code reuse public class bankaccount. { this. balance = balance;} public void deposit(double amount) { balance = balance + amount; } public void withdraw(double amount) { balance = balance - amount; } public double getbalance() * interestrate / extends keyword says we"re creating a subclass (in this example a subclass of the bankaccount class) The constructor of savingsaccount calls implicitly the default constructor of bankaccount. addinterest() is a new method. Inheriting from a class differs from realizing an interface: The subclass inherits behavior and the state of the super class; Single inheritance is when children inherit characteristics from only one parent. Multiple inheritance is when children inherit characteristics from more than one parent. Derived classes: class hierachy: the super classes can be used to implement specialized classes. For example: student, employee, faculty, and staff: classes can be derived from the classes derived from the super class, etc. , resulting in a class hierarchy.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents