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
-
It determines the relationship between the two objects such as one-to-one, one-to-many etc.
-
It determines the complexity of the objects after combining them.
-
It determines the relationship between the objects in a directional line and shows the has-a relationship.
-
It hides the implementation details of the system.
-
None of the above
B
Correct answer
Explanation
This is true about composition and it is the more restrictive form of aggregation.
-
TreeMap is the class of Map interface.
-
HashMap inherits SortedMap interface.
-
HashMap is not synchronised.
-
Only (1) and (3) are true.
-
(1), (2) and (3) all are true.
D
Correct answer
Explanation
Yes, both the statements are true.
-
The wrapper classes do not contain any constructor.
-
All the methods of a wrapper class are static in nature.
-
The wrapper class for float is java.lang.Float.
-
Wrapper classes are contained in java.lang package.
-
All of the above
E
Correct answer
Explanation
Yes, all of the above defines the properties of wrapper class in java.
-
Object
-
Util
-
Lang
-
Swing
-
None of these
A
Correct answer
Explanation
Every class is derived from the Object class.
-
class
-
subclass
-
package
-
outside package
-
all of the above
E
Correct answer
Explanation
Public method can be accessed from any where.
-
public > protected > package-private > private
-
public > protected > private > package-private
-
public > private > package-private > protected
-
public > private > protected > package-private
-
package-private > private > package-private > protected
-
Private
-
Public
-
Protected
-
Package-private
-
None of these
D
Correct answer
Explanation
The default scope is package-private. All classes in the same package can access the method/field/class. Package-private is stricter than protected and public scopes, but more permissive than private scope.
-
class
-
subclass
-
package
-
anywhere
-
all of the above
A
Correct answer
Explanation
When the access specifier is private, it can only be accessed in the class in which it is defined.
-
Interface
-
Abstract data type
-
Class
-
API
-
Library
A
Correct answer
Explanation
It just defines methods but not their implementation.
-
BootStrap Classloader, Extension Classloader, System Classloader
-
BootStrap Classloader, System Classloader, Extension Classloader
-
Extension Classloader, BootStrap Classloader, System Classloader
-
Extension Classloader, System Classloader, BootStrap Classloader
-
None of the above
A
Correct answer
Explanation
BootStrap is the parent class loader, then comes Extension class loader, and then System class loader.
-
constructor
-
method signature
-
overriding
-
delegating
-
none of the above
C
Correct answer
Explanation
Overriding is one of the ways to achieve polymorphism in Java.
-
Extension class loader
-
System class loader
-
BootStrap class loader
-
Application class loader
-
None of the above
C
Correct answer
Explanation
Bootstrap class loader is also called as Primordial class loader.
-
All methods inside the interfaces are abstract by default.
-
The access specifiers of all the methods are protected by default.
-
The variables in interfaces are not final.
-
Both 1 and 2.
-
Both 2 and 3.
-
Dictionary
-
Stack
-
Vector
-
Properties
-
All of the above
E
Correct answer
Explanation
Dictionary,Stack,Properties and Vector are the legacy classes defined in Util package of Java.
-
Static fields are initialized before non static fields.
-
Non static fields are initialized before static fields.
-
Both static fields and non static fields are initialized at the same time.
-
It depends on the JVM.
-
None of these
A
Correct answer
Explanation
Static fields are initialized during static initialization of class whereas non static fields are initialized when instance of class is created, so static fields are initialized before non static fields.