8th Jan 2019, 11:41 PM
Lisandro Musca
Lisandro Musca - avatar
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/
9th Jan 2019, 12:42 AM
Gordon
Gordon - avatar
+ 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; }}
12th Jan 2019, 1:55 PM
zemiak
0
Thanks
9th Jan 2019, 1:05 AM
Lisandro Musca
Lisandro Musca - avatar