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
-
DESCryptoServiceProvider
-
TripleDESCryptoServiceProvider
-
RandomNumberGenerator
-
MACTripleDES
-
DES
B
Correct answer
Explanation
This .NET cryptographic class defines a wrapper object to access the CSP version of the TripleDES algorithm.
-
Interaction
-
State machine
-
Package
-
Note
-
Class
A
Correct answer
Explanation
An interaction is a behavior that comprises a set of messages exchanged among a set of objects within a particular context to accomplish a specific purpose.
-
Tagged value
-
Constraint
-
Stereotype
-
Object-oriented system
-
None of these
C
Correct answer
Explanation
A stereotype extends the vocabulary of the UML, allowing one to create new kinds of building blocks that are derived from existing ones, but that are specific to one's problems.
-
inheritance
-
class
-
objects
-
polymorphism
C
Correct answer
Explanation
One of the basic concepts in OOPS approach is bundling both data and functions into one unit, known as objects.
-
Data abstraction
-
Polymorphism
-
Inheritance
-
Operator overloading
C
Correct answer
Explanation
It allows classes to be reused without making any modification.
-
function overloading
-
operator overloading
-
friend function
-
virtual function
D
Correct answer
Explanation
In this method, appropriate member function could be selected at run-time polymorphism.
-
Public
-
Private
-
Protected
-
Package
C
Correct answer
Explanation
Protected is an access specifier.It allows subclasses to inherit the protected thing, even if those classes are outside the package of the super class they extend means a protected class can be inherited outside the package(another package). Protected access specifier is used with finalize method for garbage collection when an object is being garbage collected, the garbage collector will call a special method called finalize in the object. It is also used for cleanup code and to avoid circular references.
-
system is defined in the package java.lang
-
system is a class name
-
out is an object
-
all of the above
-
print is a method
D
Correct answer
Explanation
All of the above options are correct.
Print is a method. Methods have bodies, return types and they can take different types of arguments. Print function is defined in the System class.
-
System
-
Object
-
Lang
-
Exception
B
Correct answer
Explanation
Object is the class and this class is the mother of all classes. Every class in java extends class Object, means the superclass of everything. Any class that does not explicitly extends another class implicitly extends object class. For example: public class lion extends Object {} class lion, which extends class Object explicitly, public class dog {},in this example class dog extends class Object implicitly.
-
public
-
private
-
protected
-
none of these
B
Correct answer
Explanation
It is an access modifier: private means that only code within same class can access the private data members.To encapsulate the data or hide the data we use private instance variable and provide public getter and setter methods. For example: class dog { private int size; public int getSize(){ return size;} public void set Size(int s ){size =s; }}, mark the instance variable(size) private and make the getter(getSize()) and setter(setSize()) methods public.
-
MAX_VALUE
-
MIN_VALUE
-
MIN_NORMAL
-
SIZE
C
Correct answer
Explanation
The answer is correct. MIN_NORMAL is the constant variable that is not present in Long wrapper class. Instead it is present in Float and Double classes, which will return the minimum positive normal value.
-
java.lang.Enumeration
-
java.lang.Enumerations
-
java.lang.Enum
-
java.lang.reflect.Enumeration
C
Correct answer
Explanation
This answer is correct. The class java.lang. Enum exists in java.lang package. Also, all enumerations inherit java.lang.Enum superclass. This class defines several methods that are available for use by all enumerations.
-
i. and iii. are true
-
ii. and iii. are true
-
i. and iv. are true
-
ii. and iv. are true
B
Correct answer
Explanation
This answer is correct. Enum do not need to be instantiated using the new keyword. Enum can have constructors and it will be called whenever the enum object is referred.
-
i. and iii. are true
-
i. and iv. are true
-
ii. and iii. are true
-
ii. and iv. are true
D
Correct answer
Explanation
This answer is correct. An enumeration cannot inherit any other class. The enum cannot be extended, and no other class can inherit enum class. In other words, enum can never be a super class.
-
i. and iv. are true
-
i. and iii. are true
-
ii. and iii. are true
-
ii. and iv. are true
A
Correct answer
Explanation
This answer is correct. Math class has all the methods as static and it can be called without instantiating. Also, the constructor defined for Math class is declared as private.