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

Multiple choice
  1. Polymorphism

  2. Inheritance

  3. Message communication

  4. Operator overloading

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Java does not support operator overloading to maintain simplicity and avoid the complexities found in languages like C++.

Multiple choice
  1. true

  2. false

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Java passes object references by value. While you cannot change the reference itself to point to a new object outside the method, you can modify the state of the object being referenced, which is effectively call-by-reference behavior for object contents.

Multiple choice
  1. ii & iii

  2. i & ii

  3. i & iv

  4. iii & iv

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Statement ii is true because a final class cannot be extended, so abstract methods (which require implementation) cannot exist. Statement iii is true because inner classes can have any access modifier. Statement i is false (abstract classes can have final methods), and iv is false (transient variables do not have to be static).

Multiple choice
  1. attributes and names

  2. operations and names

  3. attributes, names and operations

  4. none of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In object-oriented design, an object is defined as an entity that encapsulates both data (attributes) and the behaviors (operations) that act upon that data, identified by a unique name.

Multiple choice
  1. a function returns by value

  2. an argument is passed by value

  3. a function calls to another function

  4. an argument is passed by reference

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

A copy constructor is invoked when an object is returned by value from a function, as a temporary object is created and copied to the caller. While passing by value also invokes a copy constructor, returning by value is a classic scenario where this occurs.

Multiple choice
  1. make general classes into more specific classes

  2. pass arguments to objects of classes

  3. add features to existing classes by rewriting them

  4. improves data hiding and encapsulation

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Inheritance allows a new class (derived class) to acquire the properties and behaviors of an existing class (base class), effectively creating more specific versions of general classes.

Multiple choice
  1. a class

  2. an operator

  3. a data item

  4. a member function

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

A function defined inside a class is referred to as a member function. It has access to the private and protected members of the class.

Multiple choice
  1. resolved ambiguity by specifying a particular class

  2. limits the visibility of variables

  3. informs which base class is derived

  4. ensures copying data types

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The scope resolution operator (::) is used to specify which class or namespace a member belongs to, thereby resolving ambiguity when multiple entities share the same name.