下列JavaScript定义对象的语句中,()不正确。
A: var person = {};
B: var person = new Object();
C: person =name;
D: function person(name,sex){} var personObj = new person();
A: var person = {};
B: var person = new Object();
C: person =name;
D: function person(name,sex){} var personObj = new person();
举一反三
- 【多选题】定义了如下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("猪八戒")};
- 下列方法中,能正确创建 JavaScript 对象的是( )。 A: var txt = new Object[name:"George",price:25] B: var txt = new Object(name:"George",price:25) C: var txt = new Object{name:"George",price:25} D: var txt = new Object({name:"George",price:25})
- 下列方法中,能正确创建 JavaScript 对象的是( )。 A: var txt = new Object[name:"George",price:25] B: var txt = new Object(name:"George",price:25) C: var txt = new Object{name:"George",price:25} D: var txt = new Object({name:"George",price:25})
- class Person { String name; int age; [br][/br] public Person(String name, int age) { super(); this.name = name; this.age = age; } @Override public boolean equals(Object obj) { Person person=null; if(obj instanceof Person) person=(Person)obj; if(name.equals(person.name)&&age==person.age) return true; return false; } } class Test{ public static void main(String[] args) { Person person1 = new Person("张三", 12); Person person2 = new Person("张三", 12); System.out.println(person1.equals(person2));//运行结果是? } } 程序运行结果是什么? A: true B: false
- 以下能够创建一个对象的是( )。 A: var obj=new Object( ) ; B: var obj=function(name){this.name=name ; }<br> var p1=new obj( "张三" ) ; C: var obj={ name : "张三" ; } D: var obj=Object.create( { name: "张三" } ) ;