在对象的方法中访问属性name的语法为()。
A: self.name
B: this.name
C: self.name()
D: this.name()
A: self.name
B: this.name
C: self.name()
D: this.name()
举一反三
- 以下代码中,实例方法定义正确的是() A: class Student: def setName(self,name): self.name=name B: class Student: def setName(name): self.name=name C: class Student: def setName(self): self.name=name D: class Student: def setName(name,self): self.name=name
- 以下有关类的声明,正确的是 A: class Student(object) def __init__(self, name, score): self.name = name self.score = score B: class Student(object) def __init__(self, name, score) self.name = name self.score = score C: class Student(object): def __init__(self, name, score): self.name = name self.score = score D: class Student(object): def __int__(self, name, score): self.name = name self.score = score
- {class Student:def __init__(self, name):self.name = namedef out(self):print('name:', self.name)终端应如何输入(创建实例)______、(调用方法)______,使其可以输出“name:王芳”}
- 访问如下json对象中的name属性的方式是:var stu={name:"张三",age:20} A: stu[name] B: stu.name C: stu->name D: this.name
- 声明一个对象,给它加上name属性和show方法显示其name值,以下代码中正确的是() A: varobj=[name:"zhangsan",show:function(){alert(name);}]; B: varobj=,name:"zhangsan",show:”alert(this.name)”-; C: varobj={name:"zhangsan",show:function(){alert(name);}}; D: varobj={name:"zhangsan",show:function(){alert(this.name);}};