View Single Post
  #1 (permalink)  
Old 08-07-2007, 02:49 AM
mathias mathias is offline
Member
 
Join Date: Jul 2007
Posts: 40
mathias is on a distinguished road
Help with constructor in java
Hi, I've a question about this code:
Code:
public class Test { public Test(){} public static void main(String args[]) { System.out.println(new Test().i); } int i; }
The Java book I'm consulting says that when you provide a parameter less constructor, you replace the Java-provided default constructor. It also states that the Java-provided default constructor initialises all attributes to a default value for example zero for an integer.

However, if the above code is really replacing the default constructor, then how is int i being set to zero?

I suppose in a way this seems a weird question, it's just I'm trying to get a good understanding of the basics.

Thanks.
Reply With Quote
Sponsored Links