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: 613
posted
0
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
posted
0
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
posted
0
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).]
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.