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?()A、 HelloB、 Hello FooC、 Hello worldD、 Compilation fails.E、 The code does not run.

题目

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?()

  • A、 Hello
  • B、 Hello Foo
  • C、 Hello world
  • D、 Compilation fails.
  • E、 The code does not run.

相似考题
更多“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?()A、 HelloB、 Hello FooC、 Hello worldD、 Compilation fails.E、 The code does not run.”相关问题
  • 第1题:

    class A {  public A() {  System.out.println(“hello from a”);  }  }  class B extends A {  public B () {  System.out.println(“hello from b”);  super();  }  }  public class Test {  public static void main(String args[]) {  A a = new B();  }  }   What is the result when main is executed?()  

    • A、 Compilation fails.
    • B、 hello from a
    • C、 hello from b
    • D、 hello from b hello from a
    • E、 hello from a hello from b

    正确答案:A

  • 第2题:

    class Super {  public int i = 0;  public Super(String text) {  i = 1; }  }  public class Sub extends Super {  public Sub(String text) {  i = 2;  }   public static void main(String args[]) {  Sub sub = new Sub(“Hello”);  System.out.println(sub.i);  }  }  What is the result?()  

    • A、 0
    • B、 1
    • C、 2
    • D、 Compilation fails.

    正确答案:C

  • 第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?()  

    • A、 baz =
    • B、 baz = null
    • C、 baz = blue
    • D、 Compilation fails.
    • E、 An exception is thrown at runtime.

    正确答案:E

  • 第4题:

    public class Test {  public static void main(String args[]) {  class Foo {  public int i = 3; }  Object o = (Object)new Foo();   Foo foo = (Foo)o;  System.out.println(“i = “ + foo.i); }  }  What is the result?()  

    • A、 i = 3
    • B、 Compilation fails.
    • C、 A ClassCastException is thrown at line 6.
    • D、 A ClassCastException is thrown at line 7.

    正确答案:A

  • 第5题:

    public class Foo {  public static void main(String[] args) {  try {  return;  } finally {  System.out.println( “Finally” );  }  }  }  What is the result?()

    • A、 Finally
    • B、 Compilation fails.
    • C、 The code runs with no output.
    • D、 An exception is thrown at runtime.

    正确答案:A

  • 第6题:

    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?()  

    • A、 true
    • B、 false
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:D

  • 第7题:

    单选题
    class super (  public int I = 0;  public super (string text) (  I = 1  )  )  public class sub extends super (  public sub (string text)   ( i= 2  )  public static void main (straing args[])   (  sub sub = new sub (“Hello”);  system.out. PrintIn(sub.i);  )    )   What is the result?()
    A

     Compilation will fail.

    B

     Compilation will succeed and the program will print “0”

    C

     Compilation will succeed and the program will print “1”

    D

     Compilation will succeed and the program will print “2”


    正确答案: A
    解析: 暂无解析

  • 第8题:

    单选题
    class Super {  public int i = 0;  public Super(String text) {  i = 1; }  }  public class Sub extends Super {  public Sub(String text) {  i = 2;  }   public static void main(String args[]) {  Sub sub = new Sub(“Hello”);  System.out.println(sub.i);  }  }  What is the result?()
    A

     0

    B

     1

    C

     2

    D

     Compilation fails.


    正确答案: B
    解析: This code is perfectly legal and the answer is C. 

  • 第9题:

    单选题
    public class X {   public static void main (String[]args)   {   string s = new string (“Hello”);   modify(s);   System.out.printIn(s);   }   public static void modify (String s)  {   s += “world!”;      }   }      What is the result?()
    A

     The program runs and prints “Hello”

    B

     An error causes compilation to fail.

    C

     The program runs and prints “Hello world!”

    D

     The program runs but aborts with an exception.


    正确答案: B
    解析: 暂无解析

  • 第10题:

    单选题
    public class Foo {  public static void main(String[] args) {  try {  return;  } finally {  System.out.println( “Finally” );  }  }  }  What is the result?()
    A

     Finally

    B

     Compilation fails.

    C

     The code runs with no output.

    D

     An exception is thrown at runtime.


    正确答案: B
    解析: 暂无解析

  • 第11题:

    单选题
    class A {  public A() {  System.out.println(“hello from a”);  }  }  class B extends A {  public B () {  System.out.println(“hello from b”);  super();  }  }  public class Test {  public static void main(String args[]) {  A a = new B();  }  }   What is the result when main is executed?()
    A

     Compilation fails.

    B

     hello from a

    C

     hello from b

    D

     hello from b hello from a

    E

     hello from a hello from b


    正确答案: D
    解析: Call to super must be first statement in constructor. 

  • 第12题:

    单选题
    public class Test {  public static void main(String[] args) {  String str = NULL;  System.out.println(str);  }  }   What is the result?()
    A

     NULL

    B

     Compilation fails.

    C

     The code runs with no output.

    D

     An exception is thrown at runtime.


    正确答案: C
    解析: NULL should be "null".

  • 第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?()  

    • A、 true
    • B、 null
    • C、 false
    • D、 Compilation fails.
    • E、 The code runs with no output.
    • F、 An exception is thrown at runtime.

    正确答案:A

  • 第14题:

    public class Test {  public static void main(String[] args) {  String str = NULL;  System.out.println(str);  }  }   What is the result?()  

    • A、 NULL
    • B、 Compilation fails.
    • C、 The code runs with no output.
    • D、 An exception is thrown at runtime.

    正确答案:B

  • 第15题:

    public class foo {  public static void main (String[]args) {  String s;  system.out.printIn (“s=” + s);  }  }   What is the result?()  

    • A、 The code compiles and “s=” is printed.
    • B、 The code compiles and “s=null” is printed.
    • C、 The code does not compile because string s is not initialized.
    • D、 The code does not compile because string s cannot be referenced.
    • E、 The code compiles, but a NullPointerException is thrown when toString is called.

    正确答案:C

  • 第16题:

     public class X {   public static void main (String[]args)   {   string s = new string (“Hello”);   modify(s);   System.out.printIn(s);   }   public static void modify (String s)  {   s += “world!”;      }   }      What is the result?()    

    • A、 The program runs and prints “Hello”
    • B、 An error causes compilation to fail.
    • C、 The program runs and prints “Hello world!”
    • D、 The program runs but aborts with an exception.

    正确答案:A

  • 第17题:

    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) {}   }  

    • A、Code fragment a.
    • B、Code fragment b.
    • C、Code fragment c.
    • D、Code fragment d.
    • E、Code fragment e.

    正确答案:A

  • 第18题:

    class super (   public int I = 0;   public super (string text) (   I = 1   )   )     public class sub extends super (   public sub (string text) (   i= 2   )   public static void main (straing args) (  sub sub = new sub (“Hello”);   system.out. PrintIn(sub.i);  )   )   What is the result?()

    • A、 Compilation will fail.
    • B、 Compilation will succeed and the program will print “0”
    • C、 Compilation will succeed and the program will print “1”
    • D、 Compilation will succeed and the program will print “2”

    正确答案:A

  • 第19题:

    单选题
    public class Foo {   public void main (String args) {   system.out.printIn(“Hello World.”);   }   }   What is the result? ()
    A

     An exception is thrown.

    B

     The code does no compile.

    C

     “Hello World.” Is printed to the terminal.

    D

     The program exits without printing anything.


    正确答案: A
    解析: 暂无解析

  • 第20题:

    单选题
    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?()
    A

     baz =

    B

     baz = null

    C

     baz = blue

    D

     Compilation fails.

    E

     An exception is thrown at runtime.


    正确答案: C
    解析: A java.lang.ArrayIndexOutOfBoundsException is thrown because of line 3, should be args[0].

  • 第21题:

    单选题
    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) {}   }
    A

    Code fragment a.

    B

    Code fragment b.

    C

    Code fragment c.

    D

    Code fragment d.

    E

    Code fragment e.


    正确答案: C
    解析: 暂无解析

  • 第22题:

    单选题
    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?()
    A

     Hello

    B

     Hello Foo

    C

     Hello world

    D

     Compilation fails.

    E

     The code does not run.


    正确答案: E
    解析: 暂无解析

  • 第23题:

    单选题
    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?()
    A

     true

    B

     null

    C

     false

    D

     Compilation fails.

    E

     The code runs with no output.

    F

     An exception is thrown at runtime.


    正确答案: B
    解析: 暂无解析