O GoConqr está de visual novo! Conte para nós o que você achou.

Mapa mental

Inheritance

Hadley Browder Inglês

Conteúdo do mapa

Inheritance

  1. inheritance: the process of extending a class in OOP

    • the original class is called the parent class, base class, or superclass
    • the new class is called the child class, subclass, or derived class
    • you extend a class by using the extends keywork in a class declaration, after the class name and before the parent class
      • all Java classes automatically extend the java.lang.Object class
      • a class can only extend one class
  2. the is-a relationship

    • when you create a new class by inheritance, the subclass and the superclass have an "is-a" relationship
      • a subclass is a special type of its superclass
        • the is-a relationship does not go the other way
      • a subclass inherits all public methods and fields of its superclass
      • it is legal to assign an instance of a subclass to a reference variable of the parent type
  3. accessibility

    • from within a subclass you can access its superclass's public and protected methods and fields, but not the superclass's private methods
    • if the subclass and the superclass are in the same package, you can also access the superclass's default methods and fields
  4. method overriding

    • you can change the behavior of a method in the parent class
      • happens when you write in a subclass a method that has the same signature as a method in the parent class
        • simply write the new method in the subclass
        • you can override the superclass's public and protected methods, and if the subclass and superclass are in the same package, you can override a method with the default access level
      • if only the name is the same but the list of arguments is not, then it is method overloading
    • you cannot override a final method
  5. calling the superclass's constructors

    • when you instantiate a child class by invoking one of its constructors, it calls the no-argument constructor of the direct parent class
      • you can explicitly call the parent's constructor from a subclass's constructor by using the super keyword, but it must be the first statement in the constructor
        • the super keyword can also be used to call a hidden member or an overridden method in a superclass
  6. type casting

    • you can only cast an instance of a subclass to its parent class - called upcasting
    • downcasting to a sublcass is only allowed if the parent class reference is already pointing to an instance of the subclass
  7. final classes

    • you can prevent others from extending your class by making it final using the keyword final in the class declaration
  8. the instanceof keyword

    • can be used to test if an object is of a specified type

Informações

Descrição
Mapa Mental sobre Inheritance, criado por Hadley Browder em 21-11-2019.
Criado por
Hadley Browder
Visualizações
0
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?