niusouti.com

单选题public static void test(String str) { int check = 4;  if (check = str.length()) {  System.out.print(str.charAt(check -= 1) +“, “);  } else {  System.out.print(str.charAt(0) + “, “);  }  }  and the invocation:  test(”four”);  test(”tee”); test(”to”);  W

题目
单选题
public static void test(String str) { int check = 4;  if (check = str.length()) {  System.out.print(str.charAt(check -= 1) +“, “);  } else {  System.out.print(str.charAt(0) + “, “);  }  }  and the invocation:  test(”four”);  test(”tee”); test(”to”);  What is the result?()
A

 r, t, t,

B

 r, e, o,

C

 Compilation fails.

D

 An exception is thrown at runtime.


相似考题
更多“public static void test(String str) { int check = 4;  if (ch”相关问题
  • 第1题:

    单选题
    10. class Line {  11. public class Point { public int x,y; }  12. public Point getPoint() { return new Point(); }  13. }  14. class Triangle {  15. public Triangle() {  16. // insert code here  17. }  18. }  Which code, inserted at line 16, correctly retrieves a local instance of a Point object?()
    A

     Point p = Line.getPoint();

    B

     Line.Point p = Line.getPoint();

    C

     Point p = (new Line()).getPoint();

    D

     Line.Point p = (new Line()).getPoint();


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

  • 第2题:

    单选题
    public class test {  public static void add3 (Integer i)  int val = i.intValue ( );  val += 3;  i = new Integer (val);  } public static void main (String args [ ] )  {  Integer  i = new Integer (0);  add3 (i);  system.out.printIn (i.intValue ( )  );  } What is the result?()
    A

     Compilation will fail.

    B

     The program prints “0”.

    C

     The program prints “3”.

    D

     Compilation will succeed but an exception will be thrown at line 3.


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

  • 第3题:

    多选题
    Which statements concerning the event model of the AWT are true?()
    A

    At most one listener of each type can be registered with a component.

    B

    Mouse motion listeners can be registered on a List instance.

    C

    There exists a class named ContainerEvent in package java.awt.event.

    D

    There exists a class named MouseMotionEvent in package java.awt.event.

    E

    There exists a class named ActionAdapter in package java.awt.event.


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

  • 第4题:

    单选题
    1. class A {  2. public byte getNumber ()  {  3.   return 1;  4.   }  5. }  6.    7. class B extends A {  8. public short getNumber()  {  9.  return 2;  10. }  11.    12. public static void main (String args[]) {   13.    B  b = new B ();  14.      System.out.printIn(b.getNumber())     15.   }  16. }    What is the result?()
    A

     Compilation succeeds and 1 is printed.

    B

     Compilation succeeds and 2 is printed.

    C

     An error at line 8 causes compilation to fail.

    D

     An error at line 14 causes compilation to fail.

    E

     Compilation succeeds but an exception is thrown at line 14.


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

  • 第5题:

    单选题
    public class AssertStuff {  public static void main(String [] args) {  int x= 5;  int y= 7;  assert (x> y): “stuff”;  System.out.println(”passed”);  }  }  And these command line invocations:java AssertStuff java -ea AssertStuff What is the result?()
    A

     passed stuff

    B

     stuff passed

    C

     passed      An AssertionError is thrown with the word “stuff” added to the stack trace.

    D

     passed      An AssertionError is thrown without the word “stuff” added to the stack trace.

    E

     passed      An AssertionException is thrown with the word “stuff” added to the stack trace.

    F

     passed     An AssertionException is thrown without the word “stuff” added to the stack trace.


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

  • 第6题:

    单选题
    public class WhileFoo {   public static void main (String args) {   int x= 1, y = 6;   while (y--) {x--;}   system.out.printIn(“x=” + x “y =” + y);   }   }   What is the result?()
    A

     The output is x = 6 y = 0

    B

     The output is x = 7 y = 0

    C

     The output is x = 6 y = -1

    D

     The output is x = 7 y = -1

    E

     Compilation will fail.


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

  • 第7题:

    单选题
    What is the result?()
    A

    Compilation fails because of an error in line 3.

    B

    Compilation fails because of an error in line 7.

    C

    Compilation fails because of an error in line 9.

    D

    If you define D e = new E(),then e.bMethod() invokes the version of bMethod() defined in Line 5.

    E

    If you define D e = (D)(new E()),then e.bMethod() invokes the version of bMethod() defined in Line 5.

    F

    If you define D e = (D)(new E()),then e.bMethod() invokes the version of bMethod() defined in Line 9.


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

  • 第8题:

    单选题
    1.public class test (  2.public static void main (String args[])    {  3.int  i = 0xFFFFFFF1;  4.int  j = ~i;  5.    6.}  7.)    What is the decimal value of j at line 5?()
    A

     0

    B

     1

    C

     14

    D

     –15

    E

     An error at line 3 causes compilation to fail.

    F

     An error at line 4 causes compilation to fail.


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

  • 第9题:

    单选题
    What will be written to the standard output when the following program is run?()  public class Qd803 {   public static void main(String args[]) {   String word = "restructure";   System.out.println(word.substring(2, 3));   }   }
    A

    est

    B

    es

    C

    str

    D

    st

    E

    s


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

  • 第10题:

    多选题
    AnInterface is an interface.   AnAdapter0 is a non-abstract, non-final class with a zero argument constructor.   AnAdapter1 is a non-abstract, non-final class without a zero argument constructor, but with a constructor that takes one int argument.    Which two construct an anonymous inner class?()
    A

    AnAdapter1 aa=new AnAdapter1(){}

    B

    AnAdapter0 aa=new AnAdapter0(){}

    C

    AnAdapter0 aa=new AnAdapter0(5){}

    D

    AnAdapter1 aa=new AnAdapter1(5){}

    E

    AnInterface a1=new AnInterface(5){}


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

  • 第11题:

    单选题
    A UNIX user named Bob wants to replace his chess program with a new one, but he is hot sure where the old one is installed. Bob is currently able to run a Java chess program starting from his home directory /home/bob using the command:  java -classpath /test:/home/bob/downloads/* .jar games.Chess  Bob‟s CLASSPATH is set (at login time) to:  /usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/* .jar  What is a possible location for the Chess.class file?()
    A

     /test/Chess.class

    B

     /home/bob/Chess.class

    C

     /test/games/Chess.class

    D

     /usr/lib/games/Chess.class

    E

     /home/bob/games/Chess.class

    F

     inside jarfile /opt/java/lib/Games.jar (with a correct manifest)

    G

     inside jarfile /home/bob/downloads/Games.jar (with a correct manifest)


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

  • 第12题:

    单选题
    1. public class returnIt (  2. returnType methodA(byte x, double y) (  3. return (short) x/y * 2;  4. )  5. )   What is the valid returnType for methodA in line 2?()
    A

     Int

    B

     Byte

    C

     Long

    D

     Short

    E

     Float

    F

     Double


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

  • 第13题:

    单选题
    Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:  import java.io.*;  class Food implemertts Serializable {int good = 3;}  class Fruit externds Food {int juice = 5;}  public class Banana extends Fruit {  int yellow = 4;  public static void main(String [] args) {  Banana b = new Banana(); Banana b2 = new Banana();  b.serializeBanana(b); // assume correct serialization  b2 = b.deserializeBanana(); // assume correct  System.out.println(”restore “+b2.yellow+ b2.juice+b2.good);  }  // more Banana methods go here  }  What is the result?()
    A

     restore 400

    B

     restore 403

    C

     restore 453

    D

     Compilation fails.

    E

     An exception is thrown at runtime.


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

  • 第14题:

    单选题
    Given the fully-qualified class names:  com.foo.bar.Dog  com.foo.bar.blatz.Book  com.bar.Car  com.bar.blatz.Sun  Which graph represents the correct directory structure for a JAR file from which those classes can be used by the compiler and JYM?()
    A

     Jar A

    B

     Jar B

    C

     Jar C

    D

     Jar D

    E

     Jar E


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

  • 第15题:

    单选题
    package geometry;  public class Hypotenuse {  public InnerTriangle it = new InnerTriangle();  class InnerTriangle {  public int base;  public int height;  }  }  Which is true about the class of an object that can reference the variable base? ()
    A

     It can be any class.

    B

     No class has access to base.

    C

     The class must belong to the geometry package.

    D

     The class must be a subclass of the class Hypotenuse.


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

  • 第16题:

    多选题
    import java.awt*;   public class X extends Frame (   public static void main(string args) (  X x = new X ();   X.pack();   x.setVisible(true);  )  public X () (   setlayout (new GridLayout (2,2));   Panel p1 = new panel();    Add(p1);    Button b1= new Button (“One”);    P1.add(b1);   Panel p2 = new panel();    Add(p2);   Button b2= new Button (“Two”);    P2.add(b2);    Button b3= new Button (“Three”);   add(b3);   Button b4= new Button (“Four”);   add(b4);   )   )   Which two statements are true? ()
    A

    All the buttons change height if the frame height is resized.

    B

    All the buttons change width if the Frame width is resized.

    C

    The size of the button labeled “One” is constant even if the Frame is resized.

    D

    Both width and height of the button labeled “Three” might change if the Frame is resized.


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

  • 第17题:

    单选题
    1. public class ReturnIt {  2. return Type methodA(byte x, double y) {  3. return (long)x / y * 2;  4. }  5. }  What is the narrowest valid returnType for methodA in line2?()
    A

     int

    B

     byte

    C

     long

    D

     short

    E

     float

    F

     double


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

  • 第18题:

    单选题
    Which statement about static inner classes is true? ()
    A

     An anonymous class can be declared as static.

    B

     A static inner class cannot be a static member of the outer class.

    C

     A static inner class does not require an instance of the enclosing class.

    D

     Instance members of a static inner class can be referenced using the class name of the static inner class.


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

  • 第19题:

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


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

  • 第20题:

    多选题
    public class Parent {  public int addValue( int a, int b) {     int s;     s = a+b;     return s;     }     }  class Child extends Parent {  }  Which methods can be added into class Child?()
    A

    int addValue( int a, int b ){// do something...}

    B

    public void addValue (){// do something...}

    C

    public int addValue( int a ){// do something...}

    D

    public int addValue( int a, int b )throws MyException {//do something...}


    正确答案: D,C
    解析: 此题涉及方法重载(overload),方法重写(override)以及类派生时方法重写的规则。方法重载的规则是:
    一、参数列表必须不同,个数的不同完全可以,如果个数相同则参数类型的不同不能引起歧意,例如int 和long,float和double就不能作为唯一的类型不同;
    二、返回值可以不同,但是不能是重载时唯一的不同点(这点和c++中不同,c++中返回类型必须一致)。
    方法重写发生在类继承时,子类可以重写一个父类中已有的方法,必须在返回类型和参数列表一样时才能说是重写,否则就是重载,java中方法重写的一个重要而且容易被忽略的规则是重写的方法的访问权限不能比被重写的方法的访问权限低!重写的另一个规则是重写的方法不能比被重写的方法抛弃(throws)更多种类的异常,其抛弃的异常只能少,或者是其子类,不能以抛弃异常的个数来判断种类,而应该是异常类层次结果上的种类。此题中答案a的错误就是重写的访问权限比被重写的方法的低,而b,c都属于重载,d的错误在于比被重写的方法抛弃了更多种类的异常。

  • 第21题:

    单选题
    public class Person {  private String name, comment;  private int age;  public Person(String n, int a, String c) {  name = n; age = a; comment = c;  }  public boolean equals(Object o) {  if(! (o instanceof Person)) return false;  Person p = (Person)o;  return age == p.age && name.equals(p.name);  }  }  What is the appropriate definition of the hashCode method in class Person?()
    A

     return super.hashCode();

    B

     return name.hashCode() + age * 7;

    C

     return name.hashCode() + comment.hashCode() /2;

    D

     return name.hashCode() + comment.hashCode() / 2 - age * 3;


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

  • 第22题:

    单选题
    public class Alpha1 {  public static void main( String[] args ) {  boolean flag; int i=0;  do {  flag = false;  System.out.println( i++ );  flag = i < 10;  continue;  } while ( (flag)? true:false );  }  }  What is the result?()
    A

     000000000

    B

     0123456789

    C

     Compilation fails.

    D

     The code runs with no output.

    E

     The code enters an infinite loop.

    F

     An exception is thrown at runtime.


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

  • 第23题:

    单选题
    package foo;  import java.util.Vector; private class MyVector extends Vector {  int i = 1;  public MyVector() {  i = 2; } }  public class MyNewVector extends MyVector {  public MyNewVector() {  i = 4;  }  public static void main(String args[]) {  MyVector v = new MyNewVector();  }  }  What is the result?()
    A

     Compilation succeeds.

    B

     Compilation fails because of an error at line 5.

    C

     Compilation fails because of an error at line 6.

    D

     Compilation fails because of an error at line 14.

    E

     Compilation fails because of an error at line 17.


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

  • 第24题:

    单选题
    int i= 1, j= 10 ;  do (  if (i++> --j) continue;  ) while (i<5);   After execution, what are the values for I and j?()
    A

     i = 6 and j= 5

    B

     i = 5 and j= 5

    C

     i = 6 and j= 4

    D

     i = 5 and j= 6

    E

     i = 6 and j= 6


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