下列代码执行结果是?( ) class HelloWorld { public static void modifyString(final String str) { str = "Hello World!"; } public static void main(String[] args) { String a = new String("Hello Java"); modifyString(a); System.out.println(“a = ” + a); } }
A: a = Hello Java
B: a = Hello World
C: 代码编译错误
D: 运行时异常
A: a = Hello Java
B: a = Hello World
C: 代码编译错误
D: 运行时异常
举一反三
- 给定如下java 代码,在下划线处填入( ),代表HelloWorld 类具有main方法,可以独立运行。public class Helloworld { _______{ System.out.println( “ hello world” ) ; } } A: public static void main( String args ) B: static void main( String args[ ] ) C: public static void main( String[ ] strs ) D: public static main( String args[ ] )
- 有如下代码:public class Test{ public static void main(String args[]) { String str = new String("World"); char ch[] = {'H','e','l','l','o'}; change(str,ch); System.out.println(str + "and" + ch); } public static void change(String str, char ch[]) { str = "Changed"; ch[0] = ' C'; }}运行后输出的结果是: A: Changed and Cello B: World and Cello C: World and CelloChanged and Hello D: World and Hello
- 下面程序段的输出结果是 public class A{ public static void main(String args[]) { String str ="Hello,"; str=str+"Guys!"; System.out.println(str); } }
- 运行下面程序段的结果是:( )。 public class MyMain{ public static void main(String args){ System.out.println(“Hello Java”); } }
- public ______ HelloWorld { public static void main(String[] args) { System.out.println("Hello World !")______ }}