class Person{
String name;
Person(String name){
this.name = name;
}
}
class Employee extends Person{ // line 1
public static void main(String args[]){
Employee ee = new Employee("Bob"); //line 2
}
}
The compiler complained at line 1 saying actual and formal argument lists differ in length. Later on when I added line 2, it gave the same compiler error as line 1 at line 2 as well!
Last edited by OCAJO1 on Wed Feb 27, 2019 2:02 pm, edited 1 time in total.
Well that was kind of my point. The compiler did not even wait for line 2 to be introduced, it complained on line 1.
So if this were the exam question, and line 2 was even not present, would it be correct the answer - it will not compile?
Did you miss the section about default constructor? It explains exactly what you are asking.
Regarding whether it will compile without line 2 or not, the best way to find out is to compile it!
Yes you're right, it does hang up on line 2, not 1. I wonder what I did last time that it hung up in line 1?!
Oh well, at least the good thing is that it was just the constructors are not inherited issue.
I tried it again from scratch (without addition of any code from subsequent sections) and it failed on both //line 1 and //line 2. Looking at it again, that would make sense since the class already knows that, unlike its superclass, it does not have a single parameter constructor, even before any instantiation with a single parameter is attempted.