Question 11
EasyWhat is validation in a setter method?
- A.
Checking that a new value is acceptable before storing it
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
What is validation in a setter method?
Checking that a new value is acceptable before storing it
Printing the value
Deleting the old object
Converting the value to text
Sign up free to see the answer and a step-by-step explanation.
Which of these breaks encapsulation the most?
Making fields private
Making every field of a class public
Validating values in a setter
Providing a getter for a field
Sign up free to see the answer and a step-by-step explanation.
What is a class's public interface?
The methods (and any fields) that other code is allowed to use
Its private fields
Its file name
Its comments
Sign up free to see the answer and a step-by-step explanation.
In Python, what does a single leading underscore, as in _total, signal?
The attribute is a constant
The attribute is static
The attribute is meant for internal use, by convention only
The attribute is truly private and cannot be accessed
Sign up free to see the answer and a step-by-step explanation.
A Student class lets other code set marks to −50 directly. Which change best fixes this?
Make marks a public static field
Remove the marks field
Print a warning in main()
Make marks private and add a setter that rejects invalid values
Sign up free to see the answer and a step-by-step explanation.
A class changes its internal storage from an array to a list, and no code outside the class needs to change. Which principle made this possible?
Encapsulation
Polymorphism
Recursion
Inheritance
Sign up free to see the answer and a step-by-step explanation.
Which Java access modifier is the most restrictive?
public
default (no modifier)
protected
private
Sign up free to see the answer and a step-by-step explanation.
In Python, what does the @property decorator let you do?
Make a method run faster
Access a method as if it were an attribute, while keeping control over reading and writing
Make a class abstract
Delete an attribute
Sign up free to see the answer and a step-by-step explanation.
Which statement about a class's private members is true?
They can be used inside the class's own methods
They cannot be used at all
They are shared by all classes
They can be used anywhere in the program
Sign up free to see the answer and a step-by-step explanation.
Why should a constructor validate its arguments?
To make the class abstract
Because constructors cannot have bodies
So that the object uses less memory
So that every object starts in a valid state
Sign up free to see the answer and a step-by-step explanation.