A mobile app for a library contains a 'Book' object with information about each book. If an app feature needs to display the title of a book, which aspect of the 'Book' object would the feature need to reference?
The feature would invoke a method of the 'Book' object.
The feature would require a new variable outside the 'Book' object.
The feature would construct a new class to extract the title information.
The feature would need to reference a property of the 'Book' object.
In object-oriented programming, a property is an attribute of an object that holds data. The title of the book would typically be stored in a 'title' property of the 'Book' object. Methods perform actions or computations, not store data. Classes define the structure of an object but are a blueprint, not an individual data point. A variable declared outside the object would not inherently contain the book's title unless it is assigned from the property; therefore, the property itself is the correct source of the information.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is a property in object-oriented programming?
Open an interactive chat with Bash
What is the difference between a property and a method in OOP?
Open an interactive chat with Bash
Why wouldn’t a method be used to retrieve title information in this case?