What does the following code output?
1:public class Main { 2: int count; 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.
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. IDE would give you an alert message saying you are using a constructor name.
When the code runs, the default constructor is called and count has the default value 0 for an int. 0 value is set to count by default for instance variable.