Arshpreet Lamba wrote:
As per my knowledge, if a constructor with arguments is defined (as highlighted), then JVM wont add the default no-arg constructor . So the call to no-arg constructor should give a compile time error, But according to the answers given, it runs fine . And gives output ( -3,-1 and 5) .
Unfortunately, while your argument is correct, your conclusion is wrong. Yes, the class will not have a default constructor. However, the call to the no-arg constructor will call the constructor defined -- meaning that it should compile. Remember that with var-args, you can have no arguments too.
Henry