假设 Student类为Person类的子类,则下面()创建对象是错误的。
A: Studentbase = new Student()
B: Personbase = new Person()
C: Personchild = new Student()
D: Studentchild = new Person();
A: Studentbase = new Student()
B: Personbase = new Person()
C: Personchild = new Student()
D: Studentchild = new Person();
举一反三
- 在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()
- Student类是Person类的子类,分析下面语句,转型是否正确: Student s =(Student)new Person("张三", 23);
- 【多选题】定义了如下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("猪八戒")};
- 声明并创建一个学生类Student的对象s,下列语法格式正确的是: A: Student s = Student(); B: Student s; C: Student s = new Student(); D: Student s = new ();
- “new Person()”用于创建______类的一个实例对象。