Question 71
HardA C++ class has a member function declared 'void show() const'. Which call is allowed on a const object of the class?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
A C++ class has a member function declared 'void show() const'. Which call is allowed on a const object of the class?
obj.show()
Neither
Both
obj.setX(5) where setX is non-const
Sign up free to see the answer and a step-by-step explanation.
What is the Rule of Zero in modern C++?
Classes that don't manage resources directly shouldn't declare destructors or copy/move operations; members like smart pointers handle it
Every class needs zero members
Use zero-based indexing
Never use constructors
Sign up free to see the answer and a step-by-step explanation.
Which pattern ensures a class has exactly one instance and is often criticised for hidden global state?
Builder
Factory
Singleton
Observer
Sign up free to see the answer and a step-by-step explanation.
What does object identity mean, as distinct from equality?
Two objects have the same hash code
Two objects have the same field values
Two objects have the same class
Two references point to the very same object
Sign up free to see the answer and a step-by-step explanation.
In Python, what does @classmethod receive as its first argument?
The module
Nothing
The instance (self)
The class itself (cls)
Sign up free to see the answer and a step-by-step explanation.
In Python, what is the difference between @staticmethod and @classmethod?
They are identical
A classmethod can't be called on instances
A staticmethod receives the class
A staticmethod receives neither the instance nor the class; a classmethod receives the class
Sign up free to see the answer and a step-by-step explanation.
What is a value object in domain-driven design?
An object defined only by its values, with no identity of its own, such as an Address
A singleton
An object with a database ID
A mutable entity
Sign up free to see the answer and a step-by-step explanation.
How does a Java record (Java 16+) differ from an ordinary class?
It can't have methods
It is a concise, immutable data carrier whose constructor, accessors, equals, hashCode and toString are generated
It is mutable by default
It must extend another class
Sign up free to see the answer and a step-by-step explanation.
Why can calling an overridable method from a Java constructor be dangerous?
It creates two objects
The subclass override may run before the subclass's fields are initialised
Constructors can't call methods
It doesn't compile
Sign up free to see the answer and a step-by-step explanation.
What does it mean that Python's objects are 'first-class'?
They are created first
They can be assigned to variables, passed as arguments and returned from functions, including classes and functions
They can't be copied
They have the highest priority
Sign up free to see the answer and a step-by-step explanation.