Question 71
HardWhat is a Python Protocol (typing.Protocol) used for?
- A.
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 a Python Protocol (typing.Protocol) used for?
Abstract base classes that must be subclassed
Network protocols
Describing structural interfaces: any class with the right methods matches, without inheriting
Running code in parallel
Sign up free to see the answer and a step-by-step explanation.
Why might an abstract class have a constructor?
It can't have one
To initialise fields shared by all subclasses
To create abstract objects
To make it concrete
Sign up free to see the answer and a step-by-step explanation.
Which statement about Java interfaces' static methods is true?
They can be overridden
They are called on instances only
They can't have bodies
They are called on the interface name and are not inherited by implementing classes
Sign up free to see the answer and a step-by-step explanation.
What is the purpose of a sealed interface or class (Java 17)?
To hide it from other packages
To restrict which classes may implement or extend it, so all subtypes are known
To make it final
To make it immutable
Sign up free to see the answer and a step-by-step explanation.
What level of abstraction should a method such as processOrder() keep?
None
As many levels as possible
Only low-level byte handling
One level: call steps like validate(), charge() and ship(), not mix them with low-level details
Sign up free to see the answer and a step-by-step explanation.
A function takes a List rather than an ArrayList parameter. What does this achieve?
It requires a copy
It runs faster
Callers can pass any List implementation
It prevents modification
Sign up free to see the answer and a step-by-step explanation.
What is an anti-corruption layer?
A database constraint
A firewall rule
A layer that translates between your model and an external system's model, keeping its concepts from leaking in
An antivirus
Sign up free to see the answer and a step-by-step explanation.
Why are abstract base classes in Python checked when an object is created rather than when the class is defined?
They are checked at definition
They are never checked
Python only knows a class is incomplete when someone tries to instantiate it, so it raises TypeError then
Because of the GIL
Sign up free to see the answer and a step-by-step explanation.
What is the difference between abstraction and information hiding?
Abstraction chooses what to show (the essential operations); information hiding protects how they work
Information hiding is about inheritance
Abstraction is only for databases
They are unrelated
Sign up free to see the answer and a step-by-step explanation.
Which is an example of abstraction in an operating system?
Files, which hide disk blocks, sectors and device details
Cylinders
Disk sectors
Interrupt vectors
Sign up free to see the answer and a step-by-step explanation.