Skip to content

Instantly share code, notes, and snippets.

@XixoWreden
Last active May 2, 2019 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XixoWreden/0e1fdf2d7f35badf385146fe055882a6 to your computer and use it in GitHub Desktop.
Save XixoWreden/0e1fdf2d7f35badf385146fe055882a6 to your computer and use it in GitHub Desktop.
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
Copy link
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
Copy link
Author

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