Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Este problema se genera por la linea1, ya qie le falta de heredar el constructor
/**
* Dado el siguiente codigo.
* @author neroxixo
*/
class Vehicle{
String type = "4W";
int maxSpeed = 100;
public Vehicle(String type, int maxSpeed) {
this.type = type;
this.maxSpeed = maxSpeed;
}
}
class Car extends Vehicle{
String trans;
/**
* CONTRUCTOR Vehicle en clase Vehicle no puede aplicarse a tipos dados;
* requerido: (cadena, int)
* encontrado: no hay argumentos
* razón: las listas de argumentos reales y formales difieren en longitud
*/
Car() { //linea 1
this.trans = trans;
}
public Car(String trans){
super("4W", 150);
this.trans = trans;
}
Car(String type, int maxSpeed, String trans){
super(type, maxSpeed);
this.trans = trans; //linea 2
}
}
public class Question2 {
//Se tiene el pèdaso de código
//¿QUE ES EL RESULTADO?
public static void main(String[] args) {
Car c1 = new Car("Auto");
Car c2 = new Car("4W", 150, "Manual");
System.out.println(c1.type+" "+c1.maxSpeed+" "+c1.trans);
System.out.println(c2.type+" "+c2.maxSpeed+" "+c2.trans);
}
//A. 4W 150 Auto
//A. 4W 150 Manual
//B. Compilación fallo en la "linea 1"
//C. Compilación fallo en la "linea 2"
//D. 4W 150 Manual
//D. 4W 150 Auto
}
@XixoWreden

This comment has been minimized.

Copy link
Owner Author

XixoWreden commented Apr 30, 2019

La solución al error de compilación en la linea 1 sería que se agregará a todos los constructores que se tengan el constructor padre de Vehicle:

Car() { //linea 1
        super("4W",100);
        this.trans = trans;
    }
@XixoWreden

This comment has been minimized.

Copy link
Owner Author

XixoWreden commented May 2, 2019

Por lo tanto el resultado sería la opción B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.