About Question enthuware.ocajp.i.v7.2.1153 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
deepa.patre
Posts: 15
Joined: Thu Dec 13, 2012 9:44 am
Contact:

About Question enthuware.ocajp.i.v7.2.1153 :

Post 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....

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1153 :

Post 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.

Shortrope
Posts: 15
Joined: Sun Jun 01, 2014 8:27 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1153 :

Post 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?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1153 :

Post 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.

Shortrope
Posts: 15
Joined: Sun Jun 01, 2014 8:27 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1153 :

Post 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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests