Hierarchical inheritance in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Hierarchical inheritance in java

Why the above mentioned code of hierarchical inheritance in java not working and showing an error of arguments? https://code.sololearn.com/c007mblVjpf4/?ref=app

6th Aug 2018, 11:34 AM
harshit
harshit - avatar
1 Answer
+ 3
When you inherit from a class, the constructor of the derived class would implicitly call super() if you did not, which attempts to invoke a no-args constructor in the base class. Obviously, your base class does not have a default no-args constructor, so the most basic edit which would make your code compile properly, would be to add one to the base class. Vehicle() { // no-args constructor definition here } If adding it isn't what you want, then call super() by yourself in the derived class constructor, so that the correct constructor is invoked. E.g. Model() { super("car","Hyundai",1234); System.out.println("MODEL"+m); }
6th Aug 2018, 12:26 PM
Hatsy Rei
Hatsy Rei - avatar