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
-
methods
-
variables
-
classes
-
instance variables
A
Correct answer
Explanation
Synchronized keyword can be applied only to methods.
-
public HelloWorld(){}
-
public void HelloWorld(){}
-
private HelloWorld(){}
-
protected HelloWorld(){}
B
Correct answer
Explanation
Constructor should not contain return type.
-
cohesion
-
coupling
-
polymorphism
-
overloading
B
Correct answer
Explanation
Coupling refers to the degree of one class using members of another class; low coupling is preferred.
-
encapsulation
-
inheritance
-
polymorphism
-
transformation
B
Correct answer
Explanation
Only inherited methods can be overridden.
-
can implement only one interface
-
can implement only two interfaces
-
can implement multiple interfaces
-
cannot implement any interface
D
Correct answer
Explanation
An interface cannot implement any interface
-
OuterClass outer = new OuterClass();OuterClass.InnerClass inner = outer.new InnerClass();
-
InnerClass inner = OuterClass.new InnerClass();
-
OuterClass outer = new OuterClass();InnerClass inner = outer.new InnerClass();
-
InnerClass inner = new InnerClass();
A
Correct answer
Explanation
inner class instantiates using outer class reference.
-
processed
-
designed
-
destroyed
-
created
D
Correct answer
Explanation
In software architecture, layers are created to separate concerns and provide different levels of abstraction.
C
Correct answer
Explanation
Service primitives are categorized into four standard classes: request, indication, response, and confirm.
-
primitives
-
symbols
-
data types
-
none of these
A
Correct answer
Explanation
A service definition is formally described by the set of primitives that the service provider makes available to the service user.
-
has no body
-
returns nothing
-
is used in a base class
-
takes no arguments
A
Correct answer
Explanation
A pure virtual function is declared in a base class with no implementation, typically using the syntax = 0. It forces derived classes to provide their own implementation.
-
dynamic constructor
-
parameterized constructor
-
default constructor
-
none of the above
C
Correct answer
Explanation
A constructor that takes no arguments is known as the default constructor. If no constructor is defined, the compiler provides one automatically.
-
friend
-
static
-
virtual
-
abstract
A
Correct answer
Explanation
A friend function is a non-member function that is explicitly granted access to the private and protected members of a class. This is useful for operator overloading and specific utility functions.
-
template
-
class
-
namespace
-
class template
A
Correct answer
Explanation
Function templates are defined using the 'template' keyword followed by the template parameter list in angle brackets.
-
function name
-
class name
-
function name or class name
-
none of the above
B
Correct answer
Explanation
A constructor is a special member function that must have the exact same name as the class it belongs to.
-
class R : public P : public Q
-
class R : public P, Q
-
class R : public P, public Q
-
class R :: public P : public Q
C
Correct answer
Explanation
In C++, multiple inheritance is specified by listing the base classes separated by commas after the colon, with the access specifier for each.