定义类:      package utils;      public class Rep{  public static String twice (String s){return s+s ;}     }  再定义另一个类Demo:      //insert code here      public class Demo{  public static void main (String[]  args){      System. out .println( twice( "Hello"));      }      }  在第一行插入哪项代码,可以使程序正常编译和执行?()     A、import utils.*;B、 import utils.Rep.*;C、 import static utils.Rep.twice;D、 static import utils.Rep.twice;

定义类:      package utils;      public class Rep{  public static String twice (String s){return s+s ;}     }  再定义另一个类Demo:      //insert code here      public class Demo{  public static void main (String[]  args){      System. out .println( twice( "Hello"));      }      }  在第一行插入哪项代码,可以使程序正常编译和执行?()     

  • A、import utils.*;
  • B、 import utils.Rep.*;
  • C、 import static utils.Rep.twice;
  • D、 static import utils.Rep.twice;

相关考题:

下列程序的运行结果是【 】。public class Test {public static void main (String args[]) {String s1="hello!";System.out.println (s1.toUpperCase());}}

阅读下列代码 public class Test{ String s="One World One Dream"; public static void main(String args[]){ System. out. println(s); } } 其运行结果是A.argsB.One World One DreamC.sD.编译时出错

阅读下列代码: public class Test{ public static void main(String args[])[ System. out.println(89>>1 ); } }A.44B.45C.88D.90

public class Something {public static void main(String[] args) {Something s = new Something();System.out.println("s.doSomething() returns " + doSomething());}public String doSomething() {return "Do something ...";}}看上去很完美。

下列程序的输出结果是( )。 public class Test { public static void main (String[] args) { String s="hello"; s.replace ('r','m'); System.out.println(s); } }A.helloB.HELLOC.hemmoD.HEMMO

下面程序段的输出结果为 public class MyClass { public static void main(String args[]) { String s="Hello! How are you?"; System.out.println(s.LastIndexOf("o",16); } }A.16B.oC.uD.17

Which declarations will allow a class to be started as a standalone program?()  A、public void main(String args[])B、public void static main(String args[])C、public static main(String[] argv)D、final public static void main(String [] array)E、public static void main(String args[])

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 aC、 hello from bD、 hello from b hello from aE、 hello from a hello from b

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、 0B、 1C、 2D、 Compilation fails.

class Mineral {   static String shiny() { return "1"; }   }   class Granite extends Mineral {   public static void main(String [] args) {   String s = shiny() + getShiny();   s = s + super.shiny();   System.out.println(s);   }   static String getShiny() { return shiny(); }   }   结果为:()  A、3B、12C、111D、编译失败

public class Test {  public static void main(String[] args) {  String str = NULL;  System.out.println(str);  }  }   What is the result?()  A、 NULLB、 Compilation fails.C、 The code runs with no output.D、 An exception is thrown at runtime.

Given a class Repetition: 1.package utils; 2. 3.public class Repetition{ 4.public static String twice(Strings){returns+s;} 5.} and given another class Demo: 1.//insert code here2. 3.public class Demo{ 4.public static void main(String[]args){ 5.System.out.println(twice("pizza")); 6.} 7.} Which code should be inserted at line 1 of Demo.java to compile and run Demo to print“pizzapizza”?()A、import utils.*;B、static import utils.*;C、importutils.Repetition.*;D、static importutils.Repetition.*;E、import utils.Repetition.twice();F、import static utils.Repetition.twice;G、static import utils.Repetition.twice;

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.

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

public class Foo {  public static void main(String[] args) {  try {  return;  } finally {  System.out.println( “Finally” );  }  }  }  What is the result?()A、 FinallyB、 Compilation fails.C、 The code runs with no output.D、 An exception is thrown at runtime.

Given a class Repetition:  1. package utils;  2.  3. public class Repetition {  4. public static String twice(String s) { return s + s; }  5. }  and given another class Demo:  1. // insert code here 2.  3. public class Demo {  4. public static void main(String[] args) {  5. System.out.println(twice(”pizza”));  6. }  7. }  Which code should be inserted at line 1 of Demo.java to compile and run Demo to print“pizzapizza”?() A、 import utils.*;B、 static import utils.*;C、 import utils.Repetition.*;D、 static import utils.Repetition. *;E、 import utils.Repetition.twice();F、 import static utils.Repetition.twice;G、 static import utils.Repetition.twice;

Given the following code, write a line of code that, when inserted at the indicated location, will make the overriding method in Extension invoke the overridden method in class Base on the current object.   class Base {   public void print( ) {   System.out.println("base");   }   }   class Extention extends Base {   public void print( ) {   System.out.println("extension");   // insert line of implementation here   }   }   public class Q294d {   public static void main(String args[]) {   Extention ext = new Extention( );   ext.print( );   }   }   Fill in a single line of implementation.()

interface Beta {}  class Alpha implements Beta {  String testIt() {  return “Tested”;  }  }  public class Main1 {  static Beta getIt() {  return new Alpha();  }  public static void main( String[] args ) {  Beta b = getIt();  System.out.println( b.testIt() );  }  }  What is the result?()  A、 TestedB、 Compilation fails.C、 The code runs with no output.D、 An exception is thrown at runtime.

单选题interface Beta {}  class Alpha implements Beta {  String testIt() {  return “Tested”;  }  }  public class Main1 {  static Beta getIt() {  return new Alpha();  }  public static void main( String[] args ) {  Beta b = getIt();  System.out.println( b.testIt() );  }  }  What is the result?()A TestedB Compilation fails.C The code runs with no output.D An exception is thrown at runtime.

填空题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?()

单选题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 0B 1C 2D Compilation fails.

单选题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.

单选题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) {}   }ACode fragment a.BCode fragment b.CCode fragment c.DCode fragment d.ECode fragment e.

单选题以下的程序的执行结果为? () public class Demo{  public double getHeight(){  return 171.0;  }  public int getHeight (){  return 171;  }  public static void main(String[] args){  Demo demo = new Demo();  System.out.println(demo.getHeight());  }  }A输出171.0B输出171C第2行和第5行编译报错D第10行编译报错

单选题定义类:      package utils;      public class Rep{  public static String twice (String s){return s+s ;}     }  再定义另一个类Demo:      //insert code here      public class Demo{  public static void main (String[]  args){      System. out .println( twice( "Hello"));      }      }  在第一行插入哪项代码,可以使程序正常编译和执行?()Aimport utils.*;B import utils.Rep.*;C import static utils.Rep.twice;D static import utils.Rep.twice;

单选题class Mineral {   static String shiny() { return "1"; }   }   class Granite extends Mineral {   public static void main(String [] args) {   String s = shiny() + getShiny();   s = s + super.shiny();   System.out.println(s);   }   static String getShiny() { return shiny(); }   }   结果为:()A3B12C111D编译失败

单选题Given a class Repetition: 1.package utils; 2. 3.public class Repetition{ 4.public static String twice(Strings){returns+s;} 5.} and given another class Demo: 1.//insert code here2. 3.public class Demo{ 4.public static void main(String[]args){ 5.System.out.println(twice("pizza")); 6.} 7.} Which code should be inserted at line 1 of Demo.java to compile and run Demo to print“pizzapizza”?()Aimport utils.*;Bstatic import utils.*;Cimportutils.Repetition.*;Dstatic importutils.Repetition.*;Eimport utils.Repetition.twice();Fimport static utils.Repetition.twice;Gstatic import utils.Repetition.twice;