Question 51
MediumWhich design uses abstraction to let a program switch between MySQL and PostgreSQL easily?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
Which design uses abstraction to let a program switch between MySQL and PostgreSQL easily?
SQL strings are written inside every class
Both databases are used at once
Code depends on a Repository interface with separate implementations for each database
The database name is a global variable
Sign up free to see the answer and a step-by-step explanation.
Which feature of Python is mainly used to define abstract base classes?
The final keyword
Private methods
Interfaces
The abc module with ABC and @abstractmethod
Sign up free to see the answer and a step-by-step explanation.
A Notification interface has send(message). Email, SMS and Push classes implement it. A new WhatsApp channel is needed. What must change?
Change every caller
Rewrite all three classes
Add a WhatsApp class that implements send(); callers stay unchanged
Change the interface's method name
Sign up free to see the answer and a step-by-step explanation.
Which statement is true of C++ abstract classes?
You can have pointers and references to them but not objects
All their functions must be pure virtual
They cannot have constructors
They cannot have data members
Sign up free to see the answer and a step-by-step explanation.
Can an interface in Java have private methods?
Only abstract private methods
Only in Java 1.4
No, never
Yes, since Java 9, to share code between default methods
Sign up free to see the answer and a step-by-step explanation.
A class implements two interfaces that both define the same default method. What must it do?
Nothing, Java picks the first
Make the method static
Override the method itself (it may call either version with Interface.super.method())
It can't compile under any circumstances
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
#include <iostream>
using namespace std;
class Shape {
public:
virtual int area() = 0;
void describe() { cout << "Area: " << area(); }
virtual ~Shape() {}
};
class Rectangle : public Shape {
public:
int area() override { return 3 * 4; }
};
int main() {
Rectangle r;
r.describe();
return 0;
}
Area: 12
Area: 7
Sign up free to see the answer and a step-by-step explanation.
Can a pure virtual function in C++ have a definition (body)?
Only in templates
No, never
Only if it is static
Yes; the class stays abstract, but derived classes can call the base version explicitly
Sign up free to see the answer and a step-by-step explanation.
Which statement about Java interfaces' variables is true?
They are implicitly public, static and final (constants)
They can't be initialised
They can be private instance variables
They are re-created for each object
Sign up free to see the answer and a step-by-step explanation.
What is a marker interface?
A deprecated interface
An interface with only default methods
An interface that marks a class as abstract
An interface with no methods, used to tag a class with a capability (e.g. Serializable)
Sign up free to see the answer and a step-by-step explanation.
Compilation error
Area: 0