wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Object Reference Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Object Reference Question" Watch "Object Reference Question" New topic
Author

Object Reference Question

David Roberts
Ranch Hand

Joined: Nov 03, 2000
Posts: 142
This question is from JQPlus, I think it might be a mistake. The answer is that it will print "Hello World"
I thought is was wrong since s is undefined in main.
This is there explanation:
This is what happens in the above question.
In the method changeIt(...) you are giving a new value to the local variable but the original reference remains the same.
Question ID :970970438590
What will the following program print?
public class TestClass
{
static String str = "hello world";
public static void changeIt(String s)
{
s = "Good bye world";
}
public static void main(String[] args)
{
changeIt(str);
System.out.println(s);
}
}

David Roberts - SCJP2,MCP
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 640
u r right david
the code will give & compile time error
..coolpraful@rediffmail.com
[This message has been edited by praful thakare (edited February 10, 2001).]


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
natarajan meghanathan
Ranch Hand

Joined: Feb 01, 2001
Posts: 130
Hi guys,
I too remember taking this question. But can't recollect it is whether s or str. If it is s u guys r correct. If str then it will not change, so the output will be still "Hello world". When u post some mistakes in any test s/w, post the name of the s/w, so that it will be helpful for the concerned person to view it and correct their product.
bye.


------------------

***********************************************
Sun Certified Programmer for Java 2 Platform
***********************************************


Sun Certified Programmer for Java 2 Platform
David Roberts
Ranch Hand

Joined: Nov 03, 2000
Posts: 142
I did. JQPlus. It's in the supplemental exam. I copied and pasted it right out. There is another question I got wrong where the answer was:
Bascially, is this a valid way to create a DataInputStream?
DataInputStream DIS = new DataInputStream(FileInputStream("File.txt") ; ) ;
I saw the extra semi-colon and said no. JQPlus has some pretty bad QA, although the tests have good content.
- David
[This message has been edited by David Roberts (edited February 10, 2001).]
 
jQuery in Action, 2nd edition
 
subject: Object Reference Question