关于下列Python代码,说法正确的是class Cat: def __init__(self, age, eye_color): self.age = age self.eye_color = eye_color def voice(self): return '喵' cat = Cat(1,'blue')print(cat.age,cat.eye_color,cat.voice())
A: 程序可以运行,且输出结果为 1 blue 喵
B: 程序可以运行,且输出结果为 1 blue
C: 程序不可以运行,因为voice不是cat的某个方法,而是属性
D: 程序不可以运行,因为voice方法的返回值并不能输出
A: 程序可以运行,且输出结果为 1 blue 喵
B: 程序可以运行,且输出结果为 1 blue
C: 程序不可以运行,因为voice不是cat的某个方法,而是属性
D: 程序不可以运行,因为voice方法的返回值并不能输出
举一反三
- (7-7)阅读程序,写出程序运行结果。 //写出程序运行结果 class Eye {// 猫的眼睛类 private String color; public Eye(String color) { this.color = color; } } class Cat {// 猫类 private String name; private Eye eye; public Cat(String name, Eye eye) { this.name = name; this.eye = eye; } public boolean equals(Object obj) { Cat cat = (Cat) obj; if (this.name.equals(cat.name) && this.eye == cat.eye) return true; return false; } } public class CatDemo { public static void main(String[] args) { Eye e1=new Eye("蓝色"); Cat tom1=new Cat("Tom",e1); Cat tom2=new Cat("Tom",e1); System.out.println(tom1==tom2); System.out.println(tom1.equals(tom2)); } }
- 写出输出结果:class Student: def __init__( self, name,age=18): self.name=name self.age=agestudent=Student("李强",21)print(student.age)
- 5 Didn't you see that'blue cat/blue'cat? A: 'blue cat B: blue'cat
- Didn’t you see that ________? A: 'blue cat B: blue 'cat
- 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()