Mapa mental
Inheritance
Contenido del mapa
Inheritance
Definition
- The process of extending a class
- All classes extend the java.lang.Object class
- The process of extending a class
Performed using the "extends" keyword
- Ex: public class Child extends Parent
Uses
- extending traits from the superclass to various subclasses
- Ex: All animals might eat, but only some have fins
- So you would extend "eat" from Animal into Fish and Bird
- Ex: All animals might eat, but only some have fins
- Subclasses can access the superclass' public methods and fields
- Method Overriding
- Changing methods from the parent class using the child class
- Method Overriding
- Calling a parent class' constructor methods
- Done implicitly all the way up the chain
- Can be done explicitly through "super"
- Type Casting
- Upcasting: changing the type of a variable to its parent class
- Downcasting: changing the type to its subclass
- Only if upcasting was already used for that variable
- extending traits from the superclass to various subclasses
Prevention
- Calling something "final" will prevent it from being extended
- "instanceOf" can tell you what datatype an object is
- Will return true or false
Información
- Descripción
- Mapa Mental sobre Inheritance, creado por Ryan Plante el 21/11/2019.
- Creado por
- Ryan Plante
- Visitas
- 0
- Valoración