• 2022-07-24
    下列代码中正确的是( )。(选择两项)
    A: public String foo() { return “我爱中国”; }
    B: public void foo(){
    return ”-我爱中国”; }
    C: public String foo(){
    String s=”我爱中国”; return s; }
    D: public int foo(){
    String s=“我爱中国”; return s; }
  • A,C

    内容

    • 0

      读代码: 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(foo.i); } } 结果是:

    • 1

      关于下列代码说法正确的是( ) public class Foo{ public int add(int a,int b){ return a+b; } public static void main(String[] args){ Foo foo = null; System.out.println(foo.add(10,20)); } }

    • 2

      智慧职教: public class Foo{       int i;       static String s;       void imethod(){          }      static void smethod(){      }}已知f是Foo的一个实例,下面语句是否正确?Foo.imethod()

    • 3

      阅读程序,下面的哪个选项是正确的?( )。 class ExSuper{ String name; String nick_name; public ExSuper(String s,String t) { name = s; nick_name = t; } public String toString(){ return name; } } public class Example extends ExSuper{ public Example(String s,String t){ super(s,t); } public String toString(){ return name +"a.k.a"+nick_name; } public static void main(String args[]){ ExSuper a = new ExSuper(“First”,“1st”); ExSuper b = new Example(“Second”,“2nd”); System.out.println(“a is”+a.toString()); System.out.println("b is"+b.toString()); } }

    • 4

      智慧职教: 192.阅读以下代码:  import java.io.*;  import java.util.*;  public class foo{  public static void main (String[] args){  String s;  System.out.println("s=" + s);  }  }   输出结果应该是(    )