Mapa mental
class extension
Contenido del mapa
class extension
In the Java language, classes can be derived from other classes, thereby inheriting fields and methods from those classes.
- Excepting Object, which has no superclass, every class has one and only one direct superclass (single inheritance).
- A nested class has access to all the private members of its enclosing class—both fields and methods
A class that is derived from another class is called a subclass (also a derived class, extended class, or child class).
- he class from which the subclass is derived is called a superclass (also a base class or a parent class).
Classes can be derived from classes that are derived from classes that are derived from classes, and so on, and ultimately derived from the topmost class, Object
- Such a class is said to be descended from all the classes in the inheritance chain stretching back to Object.
A subclass does not inherit the private members of its parent class.
- if the superclass has public or protected methods for accessing its private fields, these can also be used by the subclass.
The child can inherit all the methods and fields from its parent, but can then do its own thing.
- extends is the keyword used to inherit the properties of a class. Following is the syntax of extends keyword.
To create a sub class (child) from a Java super class (parent), the keyword extends is used. You then follow the "extends" keyword with the parent class you want to extend
inheriance
- Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another
- class Vehicle { protected String brand = "Ford"; // Vehicle attribute public void honk() { // Vehicle method System.out.println("Tuut, tuut!"); } } class Car extends Vehicle { private String modelName = "Mustang"; // Car attribute public static void main(String[] args) { // Create a myCar object Car myCar = new Car();
- Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another
Información
- Descripción
- Mapa Mental sobre class extension, creado por daniela rodriguez el 17/05/2019.
- Creado por
- daniela rodriguez
- Visitas
- 0
- Historial
-
- Creado por daniela rodriguez · 15 may 2019
- Copiado por daniela rodriguez · 17 may 2019
- Valoración