• 2021-04-14
    【多选题】定义了如下Person类,下面()程序段能够正确初始化Person数组。 class Person{ private String name; public Person(String name){ this.name=name; } }
    A. Person [ ] list=new Person[ ]{new Person("孙悟空"),new Person("猪八戒")}; B. Person list[ ]=new Person[ ]{new Person("孙悟空"),new Person("猪八戒")}; C. Person[ ]  list={new Person("孙悟空"),new Person("猪八戒")}; D. Person  list=new Person[ ]{new Person("孙悟空"),new Person("猪八戒")};
  • Person [ ] list=new Person[ ]{new Person("孙悟空"),new Person("猪八戒")};;
    Person list[ ]=new Person[ ]{new Person("孙悟空"),new Person("猪八戒")};;Person[ ]  list={new Person("孙悟空"),new Person("猪八戒")};

    举一反三

    内容

    • 0

      语句“Person myTest1 = new Person(“张三”,21,60012) ” 与语句“ Person myTest1; myTest1 = new Person(“张三” , 21,60012)”等价。( )

    • 1

      以下代码执行后的结果是: public class Person { String name = “小芳”; public Person(String name) { name = “小兰”; } public void show() { this.name = “小翠”; } public static void main(String[] args) { Person p = new Person(“小凤”); System.out.print(p.name); p.show(); System.out.print(p.name); } }

    • 2

      请阅读下面的程序代码,选择正确的运行结果 Class Person{ void say(){ System.out.println(“hello”); } } class Example{ public static void main(String[] args){ Person p2 = new Person(); Person p1 = new Person(); p1.say(); p2.say();} }

    • 3

      在Java中,有如下两个类Student和Person。如果Student是Person的子类,则下列声明对象x的语句中错误的是()。 A: Person x = new Student() B: Person x = new Person() C: Student x = new Person() D: Student x = new Student()

    • 4

      阅读下面的代码: class Person{ void say(){ System.out.println("hello"); } } class Example{ public static void main(String[] args){ Person p1 = new Person(); Person p2 = new Person(); p2.say(); p1.say(); p2=null; p2.say(); } } 下列选项中,哪个是程序的输出结果?()