What does the following code output?
1: public class Main { 2: int count; //from w w w .j ava 2 s .com 3: public void Main() { 4: count = 4; 5: } 6: public static void main(String[] args) { 7: Main s = new Main(); 8: System.out.println(s.count); 9: } 10:}
A.
While the code on line 3 does compile, it is not a constructor because it has a return type.
It is a method that happens to have the same name as the class.
When the code runs, the default constructor is called and count has the default value (0) for an int.