A: p=Personp.show()
B: p=Person()p.show('李思')
C: p=Person('李思')p.show()
D: p=Person('李思')show()
举一反三
- class Person: def __init__(self,n="xxx"): self.name=n class Student(Person): def __init__(self,s="male"): self.sex=s def show(self): print(self.name,self.sex) s=Student("female") s.show() 结果:
- class Person:def __init__(self,n="xxx"):self.name=nclass Student(Person):def __init__(self,s="male"):self.sex=sdef show(self):print(self.name,self.sex)s=Student("female")s.show()结果: A: xxx male B: xxx C: 结果错误 D: xxx female
- 下面程序运行的结果是( )。class Person:def __init__(self,n="张三"): self.name=nclass Student(Person):def __init__(self,s="male"):self.sex=sdef show(self):print(self.name,self.sex)s=Student("female")s.show() A: 张三 male B: 张三 female C: 出错 D: 张三
- 定义类如下: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 Person: def __init__(self,name):self.name=name def __str__(self):return "我的名字是"+self.nameperson=Person("小明")print(person)编译能通过吗,如果通过写出结果,否则写出失败原因
内容
- 0
class Student: def __init__(self,n="xxx"): self.name=n def show(self): print(self.name) s=Student("yyy") s.show() 结果
- 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
以下有关类的声明,正确的是 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
- 3
{class Student:def __init__(self, name):self.name = namedef out(self):print('name:', self.name)终端应如何输入(创建实例)______、(调用方法)______,使其可以输出“name:王芳”}
- 4
以下代码中,实例方法定义正确的是() 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