If this source code is contained in a file called SmallProg.java, what command should be used to compile it using the JDK?() public class SmallProg { public static void main(String args[]) { System.out.println("Good luck!"); } }
第1题:
public class Foo { public void main( String[] args ) { System.out.println( “Hello” + args[0] ); } } What is the result if this code is executed with the command line?()
第2题:
public class Test { public static void main(String[] args) { String str = NULL; System.out.println(str); } } What is the result?()
第3题:
public class Test { public static void main( String[] args) { String foo = args[1]; String bar = args[2]; String baz = args[3]; System.out.println(“baz = “ + baz); } } And the command line invocation: java Test red green blue What is the result?()
第4题:
public class foo { static String s; public static void main (String[]args) { system.out.printIn (“s=” + s); } } What is the result?()
第5题:
Given a correctly compiled class whose source code is: package com.sun.sjcp; public class Commander { public static void main(String[] args) { // more code here } } Assume that the class file is located in /foo/com/sun/sjcp/, the current directory is /foo/, and that the classpath contains “.“ (current directory). Which command line correctly runs Commander?()
第6题:
Which code fragments will succeed in printing the last argument given on the command line to the standard output, and exit gracefully with no output if no arguments are given?() CODE FRAGMENT a: public static void main(String args[]) { if (args.length != 0) System.out.println(args[args.length-1]); } CODE FRAGMENT b: public static void main(String args[]) { try { System.out.println(args[args.length]); } catch (ArrayIndexOutOfBoundsException e) {} } CODE FRAGMENT c: public static void main(String args[]) { int ix = args.length; String last = args[ix]; if (ix != 0) System.out.println(last); } CODE FRAGMENT d: public static void main(String args[]) { int ix = args.length-1; if (ix > 0) System.out.println(args[ix]); } CODE FRAGMENT e: public static void main(String args[]) { try { System.out.println(args[args.length-1]); }catch (NullPointerException e) {} }
第7题:
AAA
BBB
Compilation fails.
The code runs with no output.
第8题:
true
false
Compilation fails.
An exception is thrown at runtime.
第9题:
Code fragment a.
Code fragment b.
Code fragment c.
Code fragment d.
Code fragment e.
第10题:
public static void main(String[] args){}
public static void main(String args){}
public void main(String[] args){}
public static int main(String[] args){}
第11题:
java SmallProg
avac SmallProg
javac SmallProg.java
java SmallProg main
第12题:
NULL
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第13题:
public class Alpha{ public static void main( string[] args ){ if ( args.length == 2 ) { if ( args.[0].equalsIgnoreCase(“-b”) ) System.out.println( new Boolean( args[1] )); } } } And the code is invoked by using the command: java Alpha –b TRUE What is the result?()
第14题:
声明Java独立应用程序main()方法时,正确表达是()。
第15题:
public class foo { public static void main (String[]args) { String s; system.out.printIn (“s=” + s); } } What is the result?()
第16题:
Public class test ( Public static void stringReplace (String text) ( Text = text.replace (‘j’ , ‘i’); ) public static void bufferReplace (StringBuffer text) ( text = text.append (“C”) ) public static void main (String args[]} ( String textString = new String (“java”); StringBuffer text BufferString = new StringBuffer (“java”); stringReplace (textString); bufferReplace (textBuffer); System.out.printLn (textString + textBuffer); ) ) What is the output?()
第17题:
public class Foo { public static void main(String[] args) { try { return; } finally { System.out.println( “Finally” ); } } } What is the result?()
第18题:
public class Test { public static void main(String [] args) { System.out.println(args.length > 4 && args[4].equals(“-d”)); } } If the program is invoked using the command line: java Test One Two Three –d What is the result?()
第19题:
第20题:
baz =
baz = null
baz = blue
Compilation fails.
An exception is thrown at runtime.
第21题:
The code compiles and “s=” is printed.
The code compiles and “s=null” is printed.
The code does not compile because string s is not initialized.
The code does not compile because string s cannot be referenced.
The code compiles, but a NullPointerException is thrown when toString is called.
第22题:
Hello
Hello Foo
Hello world
Compilation fails.
The code does not run.
第23题:
true
null
false
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.