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
-
Server-side code
-
Client-side code
-
Both A) and B)
-
None of the above
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).
-
Serialization
-
Threading
-
RCW
-
AppDomain
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.
-
Method calls may return only one value but objects may contain any number of methods
-
The reference count of an object must reach zero for garbage collection to take place
-
All classes must be declared in header files before they can be instantiated as objects
-
None of the above
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.
-
A class that is instantiated exactly once producing just one object of that class
-
A complete program that takes up only one line of code
-
A data structure such as a linked list that contains only one member
-
None of the above
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.
-
To sort its data structures in memory so that they can be accessed more quickly
-
To ensure that it is thread-safe by eliminating any deadlocks or race conditions
-
To break it into simpler subobjects known as "episodes"
-
To convert it into a form that can be saved to persistent storage
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.
A
Correct answer
Explanation
In Livelink WCM, the CustomProperties metadata framework supports exactly 11 distinct data types for class members to define their format.
-
Versioned Object
-
Versioned Object Base
-
Version Objects
-
Versioned Objects
-
Is another name for an Alerter.
-
Is a preset restriction created in Designer.
-
Can be used to define incompatible objects.
-
Is used to join aggregate tables.
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).
-
A static method may be invoked before even a single instance of the class is constructed.
-
A static method cannot access non-static methods of the class.
-
Abstract modifier can appear before a class or a method but not before a variable.
-
final modifier can appear before a class or a variable but not before a method.
-
Synchronized modifier may appear before a method or a variable but not before a class.
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.
-
Encapsulation is a form of data hiding.
-
A tightly encapsulated class is always immutable.
-
Encapsulation is always used to make programs run faster.
-
Encapsulation helps to protect data from corruption.
-
Encapsulation allows for changes to the internal design of a class while the public interface remains unchanged.
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).
-
A top-level class can not be called "tightly encapsulated" unless it is declared private.
-
Encapsulation enhances the maintainability of the code.
-
A tightly encapsulated class allows fast public access to member fields.
-
A tightly encapsulated class allows access to data only through accessor and mutator methods.
-
Encapsulation usually reduces the size of the code.
-
A tightly encapsulated class might have mutator methods that validate data before it is loaded into the internal data model.
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).
-
The class is declared final.
-
All local variables are declared private.
-
All method parameters are declared final.
-
No method returns a reference to any object that is referenced by an internal data member.
-
None of the above
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.
-
GFC501
-
GFC502
-
GFC503
-
None of the above
-
GFC506
-
GFC507
-
GFC508
-
None of the above
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.