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

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

3

B

12

C

111

D

编译失败


相似考题
更多“单选题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(”相关问题
  • 第1题:

    下列语句输出结果为( )。 public class test\ { public static void main (String args[]) { String s1=new String("How"); String s2=new String("How"); System.out.println(!(s1.equals(s2))); } }

    A.false

    B.true

    C.0

    D.1


    正确答案:A

  • 第2题:

    下列程序段运行的结果为 public class Test{ static void print(String s,int i){ System.out.println("String:"+s+",int:"+i); } static void print(int i, String s){ System.out.println("int:"+i+",String:"+s); } public static void main(String [] args){ print(99,"Int first"); } }

    A.String:Stringfirst,int:11

    B.int:11,String:Int first

    C.String:String first,int:99

    D.int:99,String:int first


    正确答案:D
    解析:本题考查考生阅读程序的能力。JavaApplication都是以main()方法作为入口,首先执行的是print(99,“Intfirst”),根据构造方法的参数类型选择调用方法,这里调用的是print(inti,Strings)方法,因此输出的是int:99,String:Intfirst。

  • 第3题:

    下面程序代码运行结果为( )。 import java.awt.*; public class Test { public static void main (String args[]) { String s1="a+b+c"; String s2="+"; int i=s1.lastIndexOf (s2); System.out.println(i); } }

    A.0

    B.1

    C.2

    D.3


    正确答案:D
    解析:lastIndexOf方法返回一个整数值,指出String对象内子字符串的最后一次出现的开始位置下标。如果没有找到子字符串,则返回-1。本题中子串“+”在字符串“a+b+c”中出现了两次,最后一次出现的起始位置为3。

  • 第4题:

    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 ...";

    }

    }

    看上去很完美。


    正确答案:

     

    错。看上去在main 里call doSomething 没有什么问题,毕竟两个methods 都在同一个

    class 里。但仔细看,main 是static 的。static method 不能直接call non-static methods。可改

    成"System.out.println("s.doSomething() returns " + s.doSomething());"。同理,static method 不

    能访问non-static instant variable。

  • 第5题:

    下列语句输出结果为( )。 public class test { public static void main(StringArgsl[]) { String s1=new String("How"); String s2=new String("How"); System.out.println(!(s1==s2)); } }

    A.false

    B.true

    C.1

    D.0


    正确答案:B

  • 第6题:

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

    A.hello

    B.HELLO

    C.hemmo

    D.HEMMO


    正确答案:A
    解析:String类的replace (char oldChar,char newChar)函数的作用是返回一个新的字符串,它是通过用newChar替换此字符串中出现的所有oldChar而生成的。返回的是新字符串,但是原字符串变量的值并未发生改变。因此,输出的是“hello”而不是“hemmo”。如果替换语句换为: s=s.replace('l','m');,则输出“hemmo”。

  • 第7题:

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

    A.16

    B.o

    C.u

    D.17


    正确答案:A
    解析:本题考查字符串类中常用成员函数的用法。String类的成员函数lastIndexOf()的原型是:publicintlastIndexOf(Stringstr,intfromIndex)。它用于获得字符串str在给定字符串中从fromIndex位置往回搜索第一次出现的地方。需要注意的是,在字符串中,下标是从0开始的。所以对于字符串s,下标为16的字母正好是o,从这里往前寻找字符串“o”第一次出现的位置,正好就是字符串中。它本身所在的位置。故s.lastIndexOf(“o”,16)返回的结果就是16。

  • 第8题:

    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[])

    正确答案:D,E

  • 第9题:

    final class Tree {  private static String tree = "tree ";  String getTree() { return tree; }  }  class Elm extends Tree {  private static String tree = "elm "; public static void main(String [] args) {  new Elm().go(new Tree());  }  void go(Tree t) {  String s = t.getTree()+Elm.tree+tree+(new Elm().getTree());  System.out.println(s);  } }  结果为:() 

    • A、elm elm elm elm
    • B、tree elm elm elm
    • C、tree elm tree elm
    • D、编译失败

    正确答案:D

  • 第10题:

    单选题
    final class Tree {  private static String tree = "tree ";  String getTree() { return tree; }  }  class Elm extends Tree {  private static String tree = "elm "; public static void main(String [] args) {  new Elm().go(new Tree());  }  void go(Tree t) {  String s = t.getTree()+Elm.tree+tree+(new Elm().getTree());  System.out.println(s);  } }  结果为:()
    A

    elm elm elm elm

    B

    tree elm elm elm

    C

    tree elm tree elm

    D

    编译失败


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

  • 第11题:

    单选题
    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
    解析: 暂无解析

  • 第12题:

    单选题
    下面程序的输出结果是() public class Test{  public static void main(String[] args){    String s = “abc dsf ghi”;  String[] arr = s.split(“/s”);   System.out.println(arr.length);  } }
    A

     编译报错

    B

     2

    C

     1

    D

     3


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

  • 第13题:

    classMineral{staticStringshiny(){return"1";}}classGraniteextendsMineral{publicstaticvoidmain(String[]args){Strings=shiny()+getShiny();s=s+super.shiny();System.out.println(s);}staticStringgetShiny(){returnshiny();}}结果为:()

    A.3

    B.12

    C.111

    D.编译失败


    参考答案:D

  • 第14题:

    下列程序的执行结果是______。 public class Test9 { public static void main(String[] args) { String s1 = new String("I am a girl"); String s2 = new String("I am a girl"); System.out.println (s1.equal (s2)); } }

    A.true

    B.假

    C.I amgirl

    D.都不正确


    正确答案:A
    解析:如果需要比较两个对象的值是否相同,则可以调用equal()方法,如果被比较的两个对象相等,则返回true,否则返回false。

  • 第15题:

    下列代码的执行结果是( )。 public class Test{ public static void main String args[]){ String s1=new String("welcome"); String s2=new String("welcome"); System.out.println(s1==s2); System.out.println(s1.equals(s2)); } }

    A.false,false

    B.false,true

    C.true,true

    D.true,false


    正确答案:B

  • 第16题:

    阅读下面程序 public class OperatorsAndExpressions { void equalsMethodl(){ String s1=new String("how are you"); String s2=new String("how are you"); System.out.println(s1==s2); } public static void main(String args[]){ OperatorsAndExpressions perAndExp=new OperatorsAndExpressions(); OperAndExp.equalsMethod1(); } } 程序运行结果是( )。

    A. ==

    B.true

    C.假

    D.equal


    正确答案:C

  • 第17题:

    下列代码段的执行结果是( )。 public class Test { public static void main(String args[ ]) { String s1= new String("hello"); String s2= new String("hello"); System.out.println(s1==s2); System.out.println(s1.equal(s2)); } }

    A.true false

    B.true true

    C.false true

    D.false false


    正确答案:C
    解析:本题考查比较运算符(==)的使用。比较运算符不仅可以用于基本数据类型的数据之间的比较,还可以用于复合数据类型的数据之间的比较。题中s1和s2的值虽然都是hello,但是由于它们是不同的对象,因此运算后的结果为false。如果需要比较两个对象的值是否相同,则可以调用equals()方法。所以程序最后输出false和true。

  • 第18题:

    3下列程序段运行的结果为( )。 public class Test{ static void print(String s,int i){ System.out.pdntlnC String: "+s+",int:"+i); } static void print(iht i,String s){ System.out.prinflnCint:"+i+",gtring:"+s); } public static void main(String[] args){ print(99,"Int first"); } }

    A.String:String first,int: 11

    B.int: 11,String:Int first

    C.String:String first,int:99

    D. int:99,Stfing:Int first


    正确答案:D

  • 第19题:

    下面程序的输出结果是() public class Test{  public static void main(String[] args){    String s = “abc dsf ghi”;  String[] arr = s.split(“/s”);   System.out.println(arr.length);  } }

    • A、 编译报错
    • B、 2
    • C、 1
    • D、 3

    正确答案:A

  • 第20题:

    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、3
    • B、12
    • C、111
    • D、编译失败

    正确答案:D

  • 第21题:

     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

  • 第22题:

    多选题
    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[])


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

  • 第23题:

    单选题
    现有:  class Tree {  private static String tree = "tree ";  String getTree ()  {  return tree;  }       }  class Elm extends Tree {  private static String tree = "elm ";  public static void main (String  []  args)  {       new Elm() .go (new Tree())  ;      } }  void go (Tree t)  {  String  s =  t.getTree () +Elm.tree  +  tree  +   (new  Elm() .getTree ()) ;      System.out.println (s) ;}     结果为:()
    A

     elm elm elm elm

    B

     tree elm elm elm

    C

     tree elm elm tree

    D

     tree elm tree elm


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

  • 第24题:

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

    3

    B

    12

    C

    111

    D

    编译失败


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