ACCTG 1 Lecture Notes - Lecture 4: Code Reuse, Multiple Inheritance
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.