What is true about the following program?
package mypkg; //from ww w. j av a 2 s . c o m public class Main { public void nested() { nested(2,true); } // g1 public int nested(int level, boolean height) { return nested(level); } public int nested(int level) { return level+1; }; // g2 ? public static void main(String[] v) { System.out.print(new Main().nested()); } }
D.
The three overloaded versions of nested()
compile without issue, since each method takes a different set of input arguments, making Options B and C incorrect.
The code does not compile, though, due to the first line of the main()
method, making Option A incorrect.
The no-argument version of the nested()
method does not return a value, and trying to output a void return type in the print()
method throws an exception at runtime.