Computer Knowledge
Object-Oriented Programming
2,686 Questions
Object-oriented programming questions test core computer science concepts like classes, inheritance, polymorphism, and encapsulation. The focus includes Java program structures, method overloading, and memory allocation for objects. This topic is essential for technical sections in various recruitment tests.
Java class definitionsMethod overriding rulesPolymorphism conceptsGeneric type parametersMemory allocation in objects
Object-Oriented Programming Questions
-
Data abstraction
-
Polymorphism
-
Inheritance
-
Function overloading
-
Virtual function
C
Correct answer
Explanation
It is used for reuse the code because all the properties of the base class inherit in child class.
-
data abstraction
-
encapsulation
-
polymorphism
-
inheritance
-
virtual function
A
Correct answer
Explanation
This is the definition of data abstraction, which also describes the abstract data of the class.
-
Reusability of code
-
Polymorphism
-
Data abstraction
-
Encapsulation
-
Virtual function
E
Correct answer
Explanation
This feature is not the advantage, but it is related to OOPs.
-
object is destroyed
-
object is created
-
class is destroyed
-
class is created
-
both object and class are created
B
Correct answer
Explanation
It is the correct answer because constructor invoked automatically when object is created.
-
Constructor
-
Destructor
-
Virtual function
-
Friend function
-
Static function
B
Correct answer
Explanation
It is used for this purpose.
-
Scope operator
-
Resolution operator
-
Scope resolution operator
-
Unary operator
-
Binary operator
C
Correct answer
Explanation
This operator is used for this purpose.
-
Use case
-
Interface
-
Class
-
Modeling language
-
Things
A
Correct answer
Explanation
It is a description of set of sequence of actions that a system performs that yields an observable result of value to a particular actor.
-
Object
-
Class
-
Meta class
-
Active class
-
Abstract class
D
Correct answer
Explanation
Its objects represent elements whose behavior is concurrent with other elements.
-
istream
-
ostream
-
ifstream
-
ofstream
-
fstream
E
Correct answer
Explanation
This stream class is used in C++ to perform input and output operations on to a data file.
-
istream
-
ostream
-
iostream
-
ios
-
fstream
D
Correct answer
Explanation
This stream class acts as base class in the hierarchy of file stream classes.
D
Correct answer
Explanation
This is the correct choice because there are 3 constructors of HashMap class. These are:
HashMap(): creates a Map with default initial capacity and load factor
HashMap(int initialCap, float load): creates a Map with default specified initial capacity and load factor
HashMap(m : Map): creates a Map with existing Map
C
Correct answer
Explanation
This is the correct choice because there are 4 constructors of HashTable class in Java collections framework. These constructors are:
1) Hashtable(): constructs a new, empty hashtable with a default initial capacity (11) and load factor (0.75)
2) Hashtable(int initialCapacity): constructs a new, empty hashtable with the specified initial capacity and default load factor (0.75)
3) Hashtable(int initialCapacity, float loadFactor): constructs a new, empty hashtable with the specified initial capacity and the specified load factor
4) Hashtable(Map t): constructs a new hashtable with the same mappings as the given map
C
Correct answer
Explanation
This is the correct answer. There are four constructors of TreeMap. These are:
TreeMap(): It creates an empty Map.
TreeMap(Comparator comp): The second form constructs an empty tree-based map that will be sorted by using the Comparator comp.
TreeMap(Map m): The third form initialises a tree map with the entries from m, which will be sorted by using the natural order of the keys.
TreeMap(SortedMap sm): The fourth form initialises a tree map with the entries from sm, which will be sorted in the same order as sm.
-
Abstract class
-
Final class
-
Super
-
None of these
A
Correct answer
Explanation
Abstract classes defines common properties and behaviors of other classes.
-
Interface
-
Public interface
-
Public class
-
Private class
B
Correct answer
Explanation
Serializable is a public interface to allow subtypes of non-serializable classes to be serialized. This interface is included in java.io. Serializable package has access specifier as public.