realtimethrill
07-13-2007, 02:55 PM
Hi
I've a question about this 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 parameterless constructor, you replace the Java-provided default construtor. It also states that the Java-provided default construtor initialises all attributes to a default value -e.g. zero for an integer.
However, if the above code is really replacing the default construtor, then how is int i being set to zero? (When the code is run the integer variable has the value 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.
Any answers welcome!
I've a question about this 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 parameterless constructor, you replace the Java-provided default construtor. It also states that the Java-provided default construtor initialises all attributes to a default value -e.g. zero for an integer.
However, if the above code is really replacing the default construtor, then how is int i being set to zero? (When the code is run the integer variable has the value 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.
Any answers welcome!