Page 1 of 1
About Question enthuware.ocajp.i.v7.2.1153 :
Posted: Sat Jun 29, 2013 8:09 pm
by deepa.patre
For this question...
The correct answer is just null not 'null'... because they are different right?
correct me if i am wrong....
Re: About Question enthuware.ocajp.i.v7.2.1153 :
Posted: Sun Jun 30, 2013 6:46 am
by admin
Yes, you are right. The single quotes are there just to distinguish between the option statement text and the printed text. There is nothing like like 'null'. There is null or "null".
This has now been added to the option statement to avoid the confusion.
HTH,
Paul.
Re: About Question enthuware.ocajp.i.v7.2.1153 :
Posted: Wed Jul 16, 2014 10:09 am
by Shortrope
I noticed this is true within the main method also, not just class fields:
Code: Select all
public static void main(String[] args) {
int y;
String s;
System.out.println(x +" "+ s);
}
This works fine and '0 null' is printed.
But does not work in any other method - compile time error.
Is there any other situation where default values will be assigned?
Re: About Question enthuware.ocajp.i.v7.2.1153 :
Posted: Wed Jul 16, 2014 10:52 am
by admin
I am not sure I understand what you mean. default values are never assigned automatically to local (aka automatic) variables. You must initialize them explicitly.
-Paul.
Re: About Question enthuware.ocajp.i.v7.2.1153 :
Posted: Wed Jul 16, 2014 11:49 am
by Shortrope
Sorry, my bad. I was testing this rule in several ways and copied a println statement w/out changing the vars it was printing.