Which code can be inserted to have the code print 2?
public class Main { private int v; boolean call; //from www . ja v a 2 s. com public Main() { // LINE 1 call = false; // LINE 2 } public Main(int v) { this.v = v; } public static void main(String[] args) { Main seed = new Main(); System.out.println(seed.v); } }
E.
Options A and B will not compile because constructors cannot be called without new.
Options C and D will compile but will create a new object rather than setting the fields in this one.
Option F will not compile because this()
must be the first line of a constructor.
Option E is correct.