¡GoConqr estrena diseño! Cuéntanos qué te parece.

Mapa mental

Inheritence

Sean Barnette Inglés

Contenido del mapa

Inheritence

  1. Makes classes extensible in any OOP Language

  2. The process of extending a class

    • You extend a class by making a new class
      • This new class creates a parent child relationship
        • In the new sub class you can create new methods and fields while having the ability to override existing methods and changing behavior
        • The child class can also be extended to create new parent-child relationship, unless you declare it final, therefore making it inextensible
    • Extend key words:
      • public parent class{ }
      • public Child class extends Parent {}
  3. Creates a is-a relationship between parent and child classes

    • Example: The parent class being animal, with child classes that are bird, dog, and cat
      • Each sub class "is a" animal which is why it has a is a relationship, each class is related in a way to the parent class
        • The animal class is defined with a weight field and a eat method, each sub class also has these two characteristics but like class bird has a new field being numberOfWings which is not given from the parent
      • Legal = Animal animal = new Bird, illegal= Dog dog = new Animal
        • The parents class can create new sub classes but the sub classes cannot create new values in the parent class
          • This is because the bird class is always a animal but for the illegal ,the animal is not always a dog so it would not work to define it in that manor
  4. Method Override

    • When extending a class, the sub class has the ability to change methods in the parent if it shares the same signature
    • You override a method to change its behavior
      • Can't override a final method
    • To override a method, you have to write the new method in the subclass, without having to change anything in the parent class.
      • It is legal to change the visibility of the method in the subclass, but you can only make it more visible, it is illegal to make something more private.

Información

Descripción
Mapa Mental sobre Inheritence, creado por Sean Barnette el 21/11/2019.
Creado por
Sean Barnette
Visitas
0
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?