Question 1
EasyWhat is abstraction in OOP?
- A.
Using many constructors
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 abstraction in OOP?
Using many constructors
Copying classes
Showing only the essential features of an object and hiding the implementation details
Making all fields public
Answer: C
A driver uses the steering wheel and pedals without knowing how the engine works.
Can you create an object of an abstract class directly?
Only in Java
Only if it has a constructor
Yes, always
No
Answer: D
An abstract class is incomplete; you instantiate one of its concrete subclasses instead.
What is an interface in Java?
A contract of methods that implementing classes must provide
A type of loop
A graphical user interface
A class with only private fields
Answer: A
A class that implements an interface must implement its abstract methods (or be abstract itself).
Which keyword does a Java class use to adopt an interface?
extends
inherits
implements
uses
Answer: C
class Car implements Vehicle. An interface extends other interfaces.
How is an abstract class created in C++?
By making all members static
By declaring at least one pure virtual function (= 0)
By making the constructor private
With the abstract keyword
Answer: B
virtual void area() = 0; makes the class abstract.
Can a Java class implement more than one interface?
Only two
No
Only if they are empty
Yes
Answer: D
class Duck implements Flyable, Swimmable is allowed; this is Java's form of multiple inheritance of type.
Which Python module provides support for abstract base classes?
interface
abstract
abc
oop
Answer: C
from abc import ABC, abstractmethod.
Which of these is an everyday example of abstraction?
Painting a car
Buying fuel
Driving a car with the steering wheel and pedals without knowing how the engine works
Taking a car's engine apart
Answer: C
Abstraction exposes what you need to use something and hides how it works.
Which keyword declares an abstract class in Java?
static
abstract
interface
virtual
Answer: B
For example: abstract class Shape { … }.
What is an abstract method?
A private method
A method that returns nothing
A method with an empty body that does nothing
A method declared without a body, which subclasses must implement
Answer: D
In Java: abstract double area(); in C++: virtual double area() = 0;