定义类如下:class Hello(): def __init__(self,name): self.name=name def showInfo(self): print(self.name)下面代码能正常执行的 ( )。
A: h = Helloh.showInfo()
B: h = Hello()h.showInfo('张三')
C: h = Hello('张三')h.showInfo()
D: h = Hello('admin')h.showInfo
A: h = Helloh.showInfo()
B: h = Hello()h.showInfo('张三')
C: h = Hello('张三')h.showInfo()
D: h = Hello('admin')h.showInfo
举一反三
- class Student:def __init__(self,name,age):self.name=nameself.age=agedef fun1(self):print("hello")( )def fun2(self):print("yes")child=Child("Tom",20)child.fun1()
- 以下有关类的声明,正确的是 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
- 以下代码中,实例方法定义正确的是() 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
- 定义类如下:class Test():def __init__(self,name):self.name=namedef show(self):print(self.name)下面代码能正常执行的是 ( ) A: t = Test('张三')t.show() B: t = Test()t.show('张三') C: t = Test()t.show() D: t = Testt.show('张三')
- {class Student:def __init__(self, name):self.name = namedef out(self):print('name:', self.name)终端应如何输入(创建实例)______、(调用方法)______,使其可以输出“name:王芳”}