Question: http://www.javacertifications.net/javacert/scjp1.6Mock.jsp
No questions -20
What is the result for the code below?
public class Test extends Thread { static String sName = "good"; public static void main(String argv[]) { Test t = new Test(); t.nameTest(sName); System.out.println(sName); } public void nameTest(String sName) { sName = sName + " idea "; start(); } public void run() { for(int i=0;i < 4; i++) { sName = sName + " " + i; } } }
Parameters Good B) good idea C) good idea good idea Correct answer: A
Explanations: changing a value in local methods would not have changed globally in the case of String (since the String object is immutable).
None of the answers are correct, and there is no single correct answer.
The question is very bad because it mixes two completely separate issues:
sName
nameTest()
run()
main()
, nameTest String sName, static . ,
nameTest
String sName
static
sName = sName + " idea ";
static. , , .. Test.sName.
Test.sName
run static sName , , , - "good 0 1 2 3". , , () t, sName , . , , , ( "" ). " 0", " 0 1" .. "". A - .
run
static sName
t
:
public void nameTest(String sName){ sName = sName + " idea "; start(); }
sName sName, Test.sName.
, run() , ("good")
"good"
nameTest sName . "".
, , Test.sName
nameTest. , .
Java, , , - "". , Test.sName.
, "" sName. , "", - A, 1 - .
'good' nameTest (sName), , , , nameTest . , nameTest. sName sName. , .
COPY ( arg). COPY, . good, good 0, good 0 1 ..
good
good 0
good 0 1
good 0 1 2 3
( java... ).
, :
nameTest sName String.
, , "" String - " " - sName. sName ( , ) "".
start(), run().
run() , sName.
, run() , sName , .
Source: https://habr.com/ru/post/1766923/More articles:.Net / WinForms Docking / Floating Library for .Net 4.0 - c #Convert Null to Nullable Enum (generic) - genericsAutomating cygwin through a batch file - cygwinРазмер микропроцессора - microprocessorsHow to make the work environment use more processor power? - performanceIs this a secure encryption method - javawhy 1.2 * 30 = 35? - cWhat is the .lib format in windows? - portable-executablehttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1766927/can-i-test-if-another-reference-exists-to-an-object-in-java&usg=ALkJrhj5btGZPkRsHf9EvNHk36bGFGhRqwLocal test server for PHP, similar to Django server - pythonAll Articles