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 technology web technology
  1. Server-side code

  2. Client-side code

  3. Both A) and B)

  4. None of the above

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

Code-Behind classes in ASP.NET contain server-side code that runs on the web server, not client-side code that runs in the browser. The separation allows developers to keep UI logic (server-side) separate from presentation logic (client-side).

Multiple choice technology web technology
  1. Serialization

  2. Threading

  3. RCW

  4. AppDomain

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

Serialization is the process of converting an object into a stream of bytes for storage or transmission. Threading is about execution paths, RCW is for COM interop, and AppDomain is about application isolation - none relate to object-to-bytes conversion.

Multiple choice technology programming languages
  1. Method calls may return only one value but objects may contain any number of methods

  2. The reference count of an object must reach zero for garbage collection to take place

  3. All classes must be declared in header files before they can be instantiated as objects

  4. None of the above

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

The C programming language does not support object-oriented concepts like classes, objects, method calls, or automatic garbage collection natively. Therefore, all statements describing these features are false, making 'None of the above' correct.

Multiple choice technology programming languages
  1. A class that is instantiated exactly once producing just one object of that class

  2. A complete program that takes up only one line of code

  3. A data structure such as a linked list that contains only one member

  4. None of the above

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

The singleton pattern restricts the instantiation of a class to one single instance, ensuring global access to that specific object across the application.

Multiple choice technology programming languages
  1. To sort its data structures in memory so that they can be accessed more quickly

  2. To ensure that it is thread-safe by eliminating any deadlocks or race conditions

  3. To break it into simpler subobjects known as "episodes"

  4. To convert it into a form that can be saved to persistent storage

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

Serialization converts an object's state into a format (like JSON, XML, or binary) that can be saved to disk, sent over a network, or stored in a database, and later reconstructed. It's about persistence, not performance optimization, thread safety, or decomposition.

Multiple choice technology web technology
  1. Is another name for an Alerter.

  2. Is a preset restriction created in Designer.

  3. Can be used to define incompatible objects.

  4. Is used to join aggregate tables.

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

A conditional object in Business Objects Designer is a predefined restriction that can be reused across multiple queries and universes. It's not an alerter (A), not used for defining incompatible objects (C), and not for joining aggregate tables (D).

Multiple choice technology programming languages
  1. A static method may be invoked before even a single instance of the class is constructed.

  2. A static method cannot access non-static methods of the class.

  3. Abstract modifier can appear before a class or a method but not before a variable.

  4. final modifier can appear before a class or a variable but not before a method.

  5. Synchronized modifier may appear before a method or a variable but not before a class.

Reveal answer Fill a bubble to check yourself
A,B,C Correct answer
Explanation

A: True - static methods belong to the class, not instances, so they can be called before any object is created. B: True - static methods cannot directly access instance members (non-static methods/fields) without an object reference. C: True - abstract can modify classes and methods, but not variables. D is false because final CAN modify methods (to prevent overriding). E is false because synchronized only modifies methods or code blocks, not variables.

Multiple choice technology programming languages
  1. Encapsulation is a form of data hiding.

  2. A tightly encapsulated class is always immutable.

  3. Encapsulation is always used to make programs run faster.

  4. Encapsulation helps to protect data from corruption.

  5. Encapsulation allows for changes to the internal design of a class while the public interface remains unchanged.

Reveal answer Fill a bubble to check yourself
A,D,E Correct answer
Explanation

Encapsulation hides internal implementation and protects data from unauthorized access (A, D). It allows internal changes without breaking public contracts (E). Encapsulation is not about performance (C) and does not require immutability (B).

Multiple choice technology programming languages
  1. A top-level class can not be called "tightly encapsulated" unless it is declared private.

  2. Encapsulation enhances the maintainability of the code.

  3. A tightly encapsulated class allows fast public access to member fields.

  4. A tightly encapsulated class allows access to data only through accessor and mutator methods.

  5. Encapsulation usually reduces the size of the code.

  6. A tightly encapsulated class might have mutator methods that validate data before it is loaded into the internal data model.

Reveal answer Fill a bubble to check yourself
B,D,F Correct answer
Explanation

Encapsulation improves maintainability (B). A tightly encapsulated class restricts field access to getters/setters (D). Mutators can validate data (F). Tightly encapsulated classes need not be private (A), don't need fast public access (C), and don't necessarily reduce code size (E).

Multiple choice technology programming languages
  1. The class is declared final.

  2. All local variables are declared private.

  3. All method parameters are declared final.

  4. No method returns a reference to any object that is referenced by an internal data member.

  5. None of the above

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

Tight encapsulation requires all instance variables to be private and access to them controlled via getters/setters. None of the listed options (such as declaring the class final or local variables private) are strict prerequisites for tight encapsulation.

Multiple choice technology programming languages
  1. GFC506

  2. GFC507

  3. GFC508

  4. None of the above

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

GFC507 is NOT tightly encapsulated because it declares 'String name' without any access modifier (package-private), breaking encapsulation. GFC506 and GFC508 keep their name fields private with proper access control.