0
Where is the error in this code?
3 Answers
+ 2
Lujo should accept String and int as the parameters in its constructor, as it extends Tren
https://www.sololearn.com/learn/Java/2163/
+ 1
As I can see, you changed your code yet, but this is solution for your problem before - with inheritage with different constructor parameters in derived class. In that case you can define parameters for base class constructor with super() in first line of derived constructor.
public class Code {
public static void main(String[] args) {
Train first = new Train ("Juan" , 21);
Luxury third = new Luxury();
Luxury fourth = new Luxury("Martin", true);
}}
public class Train{
String trainDriver;
int antiquity;
public Train(String name, int year){
trainDriver = name;
antiquity = year;
}}
class Luxury extends Train{
String waiter;
boolean bar;
public Luxury(){
super("Anonymous", 0);
waiter = "Anonymous";
bar = false;
}
public Luxury(String name, boolean state){
super("Anonymous", 0);
waiter = name;
bar = state;
}}
0
Thanks