• 2022-06-07
    定义类的代码如下:class Person():def __init__(self,name):self.name=namedef show(self):print(self.name)
    A: p=Personp.show()
    B: p=Person()p.show('李思')
    C: p=Person('李思')p.show()
    D: p=Person('李思')show()
  • C

    内容

    • 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