mirror of
https://github.com/Brandon-Rozek/website.git
synced 2025-10-10 15:01:15 +00:00
Website snapshot
This commit is contained in:
parent
ee0ab66d73
commit
50ec3688a5
281 changed files with 21066 additions and 0 deletions
39
content/ta/spring2018/cpsc220/apr3.md
Normal file
39
content/ta/spring2018/cpsc220/apr3.md
Normal file
|
@ -0,0 +1,39 @@
|
|||
# Lecture for April 3rd
|
||||
|
||||
## Inheritance
|
||||
|
||||
The *base class*, *super class*, or *parent class* is the initial class that we are working with. Let's say that you want to *extend* the class, or add additional functionality. The class that inherits from the parent class is called the *child class*, *subclass* or *derived class*.
|
||||
|
||||
## Child Class Syntax
|
||||
|
||||
```java
|
||||
public class Truck extends Car {
|
||||
// Truck Appropriate Fields
|
||||
// Necessary methods for truck
|
||||
}
|
||||
```
|
||||
|
||||
This code adds all the methods from Car into the Truck class. You can then add methods that is specific to a Truck into the Truck class.
|
||||
|
||||
A child class has all parent fields and access to all parent methods!
|
||||
|
||||
## Visibility Modifiers
|
||||
|
||||
Recall the words `public` and `private`
|
||||
|
||||
The `public` modifier makes the field/method accessible by any class
|
||||
|
||||
The `private` modifier makes the field/method only accessible within the method itself
|
||||
|
||||
The protected modifier makes the field/method accessible within the same class or any subclasses.
|
||||
|
||||
## Overriding a Method
|
||||
|
||||
You can override a parent class method by declaring a method in the child class with the same...
|
||||
|
||||
- name
|
||||
- number of paramters
|
||||
- parameter types
|
||||
|
||||
but this method would have different behavior!
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue