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 object property
  1. A. An instance of a class is an object

  2. C. Object is the super class of all other classes

  3. D. Objects do not permit encapsulation

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

The question asks which statement is FALSE. Objects DO permit encapsulation - it's a core OOP principle of bundling data and methods together. Option C correctly identifies the false statement.

Multiple choice object relationship
  1. A. An object with only primitive attributes

  2. C. An instance which has other objects

  3. D. None of the above

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

An aggregate object is an object that contains other objects as its parts or attributes, representing a 'has-a' relationship. This is a core concept in object-oriented design and composition.

Multiple choice oop concept
  1. A. Method Invocating

  2. B. Method Overriding

  3. C. Method Labeling

  4. D. Method Overloading

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

Method overloading allows multiple methods with the same name but different parameter lists (number or type). This differs from overriding which is about subclass behavior.

Multiple choice java exception
  1. A. protected

  2. B. extends Throwable

  3. C. implements Throwable

  4. D. serializable

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

In Java, the Exception class extends Throwable. While it is also serializable, the most fundamental architectural definition in the context of the class hierarchy is its inheritance from Throwable.

Multiple choice general knowledge science & technology
  1. Namedareas

  2. Packages

  3. Global Assembly Cache

  4. Namespaces

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

Namespaces provide a way to group related classes, objects, and functions under a single name, preventing naming conflicts and organizing code logically. This is particularly useful in large projects or when combining code from multiple sources. Named areas is not a standard programming term, packages are used in languages like Java, and Global Assembly Cache is specific to .NET assembly storage.

Multiple choice general knowledge science & technology
  1. ios

  2. fstream

  3. ostream

  4. All the above

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

In C++, ios is the base class for all I/O stream classes, fstream handles file input/output operations, and ostream is the base class for output streams. Since all three (ios, fstream, and ostream) are legitimate stream classes in C++'s I/O hierarchy, option D is the correct choice. This question tests knowledge of the C++ stream class hierarchy.

Multiple choice general knowledge science & technology
  1. Extensibility

  2. Operator not limited to operate only with primitive Data Type

  3. Both A and B

  4. Operator's Scope is increased

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

Operator overloading allows operators to work with user-defined types (extensibility) and means operators are not limited to primitive data types only. Both statements A and B are correct advantages, making 'Both A and B' the right answer. Option D about increased scope is vague - the scope isn't increased but rather extended to work with custom types.

Multiple choice general knowledge science & technology
  1. saves program development time

  2. code reusability

  3. data hiding

  4. A and B

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

Inheritance enables code reusability by allowing new classes to inherit properties and methods from existing classes, which saves program development time. Data hiding is primarily achieved through encapsulation (access specifiers), not inheritance. The advantage combines both A and B - you get reusable code that reduces development effort.

Multiple choice general knowledge science & technology
  1. Extraction Operator

  2. Insertion Operator

  3. Questionmark Colon operator

  4. Scope resolution operator

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

The scope resolution operator (::) connects a member function definition to its class when defined outside. You write ReturnType ClassName::functionName(parameters) to show this function belongs to ClassName. The extraction (>>), insertion (<<), and ternary (? :) operators serve completely different purposes in C++.

Multiple choice general knowledge science & technology
  1. C with structures

  2. C with classes

  3. C in addition to classes

  4. C in addition to structures

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

C++ was developed by Bjarne Stroustrup starting in 1979, originally called "C with Classes" because it added object-oriented features like classes to the C language. The name "C++" was coined later, playing on the increment operator in C to suggest it's an enhancement or "next version" of C.

Multiple choice general knowledge science & technology
  1. Security

  2. Portability

  3. Multiple Inheritance

  4. Multi Level Inheritance

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

Java does not support multiple inheritance of classes to avoid complexity and the diamond problem. It does support multi-level inheritance (inheritance chain) and single inheritance. Java emphasizes security through its sandbox model and bytecode verification, and portability through its JVM architecture.

Multiple choice general knowledge science & technology
  1. Method & Interface Only

  2. Encasulation

  3. Database

  4. None of the Above

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

A class in object-oriented programming is a blueprint that encapsulates data and methods together. Encapsulation bundles related data and behavior into a single unit, hiding internal details. Options A, C, and D are incorrect - classes are not just interfaces, not databases, and 'none' is wrong.