Why is it null? Java heritage

0
public class PracticaHerenciaSimple {

    public static void main(String[] args) {
        System.out.println("** CLASE PADRE VEHICULO **");

        Vehiculo vehiculo = new Vehiculo() {};// constructor por defecto creado por el compilador
        vehiculo.marca="MARCA X";
        vehiculo.modelo=2012;
        vehiculo.nombre="NOMBRE X";
       Aereo aereo= new Aereo();
       aereo.nombreAereo="NOMBRE AEREO X";
       Acuatico acuatico= new Acuatico();
       acuatico.nombreAcuatico="NOMBRE ACUATICO X";
       Avion avion= new Avion();
       avion.aerolinea="X";
        System.out.println("");
        System.out.printf("\nEn la CLASE PADRE VEHICULO se tiene "
                + "marca: %s, nombre: %s, modelo: %d", vehiculo.marca, vehiculo.nombre, vehiculo.modelo);
       vehiculo.transporte();
        System.out.println("");

        System.out.println("** SUBCLASE AEREO **");
        System.out.printf("En la clase hija AEREO se tiene marca: "
                + "%s, nombre: %s, modelo: %d, "
                + "nombre Aereo: %s\n",aereo.marca, aereo.nombre, aereo.modelo, aereo.nombreAereo);
        aereo.transporte();
    }

}
public abstract class Vehiculo {

    protected int modelo;
    protected String nombre;
    protected String marca;

    public void transporte() {
        System.out.println("\nMetodo transporte() de la clase VEHICULO");

    }
    }

The inheritance does not work, it goes out null.

    
asked by Agustin Ozuna Leguizamón 23.06.2018 в 03:55
source

1 answer

0

Since it is an abstract class, it must have an abstract method and the class that is going to use it must extend the abstract class

public class mombreClase extends claseAbstracta
    
answered by 23.06.2018 / 04:53
source