You are asked to ensure that certain attributes in a Car class should never be overridden by any child class. Which mechanism would you use to ensure this?
- @final decorator (custom)
- @property decorator
- method overriding
- private attributes
To ensure that certain attributes in a Car class should never be overridden by any child class, you can use private attributes. By convention, prefix attribute names with an underscore (e.g., _attribute) to indicate that they should not be accessed or overridden externally.
Loading...
Related Quiz
- To iterate over a list in reverse order using a for loop, one can use the _______ method of the list.
- The ____ method in Python is used to initialize a newly created object and is called every time the class is instantiated.
- Which keyword is used in Python to check a condition?
- Imagine you have a Circle class where you want the radius to always be non-negative. Which approach would you use to ensure this while still allowing direct assignment like circle.radius = 5?
- You notice a script is taking more memory than expected even after finishing its tasks. You suspect some objects aren't being garbage collected. How can you explicitly attempt to clean them up?