Mapa mental
Inheritance

Conteúdo do mapa
Inheritance
Extending a class or subclassing or inheriting a class using keyword 'extends'
- Inheritance allows you to add methods that don't exist in the original class while still retaining the original features.
- Java does not inherit from multiple classes. Can't extend a class from two different classes.
- Interface gets around this issue and supports the functionality of multiple inheritance.
- Can continue to subclass as needed. The final keyword prevents further subclassing.
- Multilevel inheritance has limits to access to distant classes. Grandparent ---> Parent ----> Child Child has no access to grandparent.
- Java does not inherit from multiple classes. Can't extend a class from two different classes.
- Inheritance allows you to add methods that don't exist in the original class while still retaining the original features.
·
- Line points towards generalization.
extends used in code: public class Parent {}
- public class Child extends Parent {}
- All Java classes automatically extend java.lang.Object Class
- Parent class is a subclass to Object class in Java
- As-Is Relationship: Animal (parent class) <--- Fox(child class)
- public class Child extends Parent {}
Accessibility
- From inside a subclass, you can use the parent class's public and protected methods and fields. You can not use the private methods. If both parent and child classes are in the same package, the child can also access the parent's default methods and fields.
- Method Overriding
- When the child class's methods are used in place of the parent class. This is done by using the same name and allows Java to have runtime polymorphism, the ability to change functionality depending on which class's method is used.
- Method Overloading
- This allows a class to have more than one method with the same name but with different parameters. This increases readability of the code.
Typecasting
- You can change the type of the subclass to the parent class's type. Also known as upcasting.
Imagens e arquivos do mapa
Informações
- Descrição
- Computer Science Mapa Mental sobre Inheritance, criado por John Poulos em 04-08-2019.
- Criado por
- John Poulos
- Visualizações
- 0
- Histórico
-
- Criado por John Poulos · 3 ago 2019
- Copiado por John Poulos · 3 ago 2019
- Copiado por John Poulos · 4 ago 2019
- Avaliação