0
Fill in the blanks to create an object of type Car and call its horn() method
Car c = ________Car(); __________();
9 Antworten
+ 3
class Vehicle:
def horn(self):
print("Beep!")
class Car(Vehicle):
def __init__(self, name, color):
self.name = name
self.color = color
obj = Car("BMW", "red")
obj.horn()
+ 2
to create an object of type Car and call its horn() method
Car c = new Car();
c.horn ();
+ 2
to create an object of type Car and call its horn() method
Car c = new Car();
c.horn ();
+ 1
;/
+ 1
why
0
waaaa thank you so much ~
0
class Vehicle:
def horn(self):
print("Beep!")
class Car(Vehicle):
def __init__(self, name, color):
self.name = name
self.color = color
obj = Car("BMW", "red")
obj.horn()
The code you have written defines a class Vehicle with a single method horn that prints "Beep!". Then you have defined another class Car that inherits from Vehicle and has an additional __init__ method to initialize the name and color attributes of the car.
Finally, you create an object obj of class Car with the arguments "BMW" and "red", and call its horn method, which will result in the following output:
0
class Person
{
int age;
string name;
public void SayHi()
{
Console.WriteLine("Hi");
}
}