Software Construction: Inheritance
Cards to learn inheritance with
Cards to learn inheritance with
Fichier Détails
Cartes-fiches | 16 |
---|---|
Langue | Deutsch |
Catégorie | Informatique |
Niveau | Université |
Crée / Actualisé | 04.01.2020 / 11.01.2020 |
Lien de web |
https://card2brain.ch/box/20200104_software_construction_inheritance
|
Intégrer |
<iframe src="https://card2brain.ch/box/20200104_software_construction_inheritance/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>
|
Créer ou copier des fichiers d'apprentissage
Avec un upgrade tu peux créer ou copier des fichiers d'apprentissage sans limite et utiliser de nombreuses fonctions supplémentaires.
Connecte-toi pour voir toutes les cartes.
The extends Keyword (Definition)
In java we extend / inherit a superclass / parent by using the extends keyword.
Defining a subclass (e.g., MemorizingDeck) as an extension of a superclass (e.g., Deck) means that when objects of the subclass are instantiated, the objects will be created by using the declaration of the subclass and of the declaration of the superclass.
Example
public class MemorizingDeck extends Deck {
private CardStack aDrawnCards;}
In java, can an objects type be chaged during run-time?
Javas Single-Rooted Class Hierarchy (Definition)
Example inheriting Fields
It will only create private final CardStack aDrawnCards = new CardStack(); (from MemorizingDeck) because aCards (from Deck) is private (and not public or protected!).
Only public or protected fields will be inherited!
(fields != methods)! (therefore methods from interface are not looked at here)
The field aCards can only be accessed if the superclass has setters / getters (as if it would be any other class).
What happens? Should work (???)
In what order are fields initialized with inheritance? (In java)
Overloading Methods (Definition)
Abstract Class vs. Interface (in Java!)
- Interface methods are implicitly abstract & cannot have implementations while abstract classes can have instance methods when a subclass uses the default behavior.
- Variables in an interface are final by default while abstract classes can have non-final variables.
- Members of an interface are public by default while abstract classes can have public, privae & protected members.
- Interfaces are used with implements and abstract classes with extends.
- Interfaces can only implement another interface, while abstract classes can extend another abstract class & implement multiple interfaces.
- A class can implement multiple interfaces but it can extend only one abstract class.
- Interface is absolutely abstract and cannot be instantiated; An abstract class also cannot be instantiated, but can be invoked if a main() exists (???).
- In comparison with abstract classes, interfaces are slow as they require extra indirection.
-
- 1 / 16
-