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. any member of the class instances

  2. only static members of class instances

  3. only integer values

  4. none of the above

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

Static member functions in C++ can access and modify only static data members of the class, not instance-specific members. This is because static functions are not bound to any particular object instance.

Multiple choice
  1. no arguments

  2. one argument

  3. two arguments

  4. an object argument

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

A default constructor is a constructor that takes no arguments. It's used to create objects without requiring any initialization parameters, initializing member variables to default values.

Multiple choice
  1. `Person

  2. ~Person

  3. :Person

  4. None of the above

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

In C++, the destructor is named by prefixing a tilde (~) to the class name. For a class named Person, the destructor would be ~Person(), which is automatically called when the object is destroyed.

Multiple choice
  1. 1

  2. 2

  3. 3

  4. 4

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

C++ has three main types of constructors: default constructor (no parameters), parameterized constructor (with parameters), and copy constructor (creates object from another object of same class).

Multiple choice
  1. 1

  2. 5

  3. 99

  4. No limit

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

A class is a blueprint or template, and you can create as many objects (instances) from it as you need, limited only by available memory. There is no theoretical limit imposed by the language itself.

Multiple choice
  1. reuse code

  2. add functionality

  3. both (1) and (2)

  4. none of the above

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

Inheritance allows derived classes to reuse code from base classes AND add new functionality, combining both benefits. This promotes code reuse and extensibility.

Multiple choice
  1. to reuse code

  2. for component based programming

  3. both (1) and (2)

  4. none of the above

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

Class libraries serve both purposes: they contain reusable code that programmers can use, and they support component-based programming by providing pre-built, tested components.

Multiple choice
  1. a user defined data type

  2. a data type

  3. a template for objects

  4. all of the above

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

A class is fundamentally a template or blueprint that defines the structure and behavior of objects. While it's also a user-defined data type, 'template for objects' best captures its role in creating instances.

Multiple choice
  1. private

  2. public

  3. protected

  4. none of the above

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

Methods (member functions) are typically declared public so they can be called from outside the class to perform operations on the object's data. Private methods exist but are less common.

Multiple choice
  1. @

  2. !

  3. :

  4. ;

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

In C++, class definitions (like struct definitions) must end with a semicolon after the closing brace. This terminates the declaration statement.