Mindmap
Inheritance
Inhalt der Mindmap
Inheritance
Extends Keyword
- adding "extends ParentClass" to the child class declaration will have the child class extend the parent class.
- Extending a class means saying the child class is a type of the parent class, like saying a bird is an animal, where bird is the child and animal is the parent.
- Allows the child class to use the methods within the parent class, but can still declare their own methods which the parent and other child classes cannot use.
- Allows one to declare an object like Animal animal = new Bird(); but not like Bird bird = new Animal();
- Allows the child class to use the methods within the parent class, but can still declare their own methods which the parent and other child classes cannot use.
- Extending a class means saying the child class is a type of the parent class, like saying a bird is an animal, where bird is the child and animal is the parent.
- adding "extends ParentClass" to the child class declaration will have the child class extend the parent class.
Accessibility
- A subclass/child class can access the superclass/parent class's public and protected methods and fields, but not private methods.
method Overriding
- Writing a method in a child class with the same name and arguments as in the parent class, the program will run the method in the child class.
- This cannot be done with final methods.
- Writing a method in a child class with the same name and arguments as in the parent class, the program will run the method in the child class.
Calling the Superclass's Constructors
- When using a child class constructor, the parent class's constructor is called, which will label the child object as an instance of the parent type as well.
- This must be done with a no-argument constructor in the parent class. If there is none, there will be a compiler error.
- When using a child class constructor, the parent class's constructor is called, which will label the child object as an instance of the parent type as well.
Calling the Superclass's Hidden Members
- using the "super" keyword, you can call a hidden member or an overridden method of the super class.
Type Casting
- You can cast an object of a child class to be an object of the parent class.
- Can be done by Child child = new Child(); Parent parent = child;
- You can cast an object of a child class to be an object of the parent class.
Final Classes
- declaring "final" before a class will not allow another class to use that one as a parent.
Instanceof Keyword
- Can be used to test if an object is of a specified type (works with child objects being tested as a parent object).
- Ex: String s = "Hello"; if(s instnaceof java.lang.String){a=true} will check if the object s is a String, which it is, so will run the inside of the if statement, making a to be true.
- Can be used to test if an object is of a specified type (works with child objects being tested as a parent object).
Informationen
- Beschreibung
- Mindmap am Inheritance, erstellt von Cody Miller am 21/11/2019.
- Erstellt von
- Cody Miller
- Aufrufe
- 0
- Bewertung