198k views
0 votes
write a class named car that has the following private member variables:yearmodel: an int that holds the car's year modelmake: a string that holds the make of the carspeed: an int that holds the car's current speed

1 Answer

2 votes

Answer: Sure, here's an example of a Car class with the requested private member variables:

Explanation:

python

Copy code

class Car:

def __init__(self, yearmodel: int, make: str, speed: int):

self.__yearmodel = yearmodel

self.__make = make

self.__speed = speed

In this example, __init__() is the constructor method of the class. It takes three parameters: yearmodel, make, and speed, and initializes the private member variables __yearmodel, __make, and __speed with their respective values.

Note that the double underscore before each member variable name makes them private, which means they cannot be accessed from outside the class without using getter and setter methods.

SPJ11

User Albert Camacho
by
8.6k points