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
-
A. An instance of a class is an object
-
C. Object is the super class of all other classes
-
D. Objects do not permit encapsulation
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.
-
A. An object with only primitive attributes
-
C. An instance which has other objects
-
D. None of the above
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.
-
A. Method Invocating
-
B. Method Overriding
-
C. Method Labeling
-
D. Method Overloading
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.
-
A. protected
-
B. extends Throwable
-
C. implements Throwable
-
D. serializable
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.
-
Namedareas
-
Packages
-
Global Assembly Cache
-
Namespaces
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.
-
ios
-
fstream
-
ostream
-
All the above
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.
-
Extensibility
-
Operator not limited to operate only with primitive Data Type
-
Both A and B
-
Operator's Scope is increased
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.
-
Cannot be inherited
-
Can be inherited at all instances
-
Can be inherited only if the derived class is inheriting from base class with public access level
-
Can be inherited only if the derived class is inheriting from base class with private access level
-
Base class
-
Derived class
-
Both A and B
-
Anyone of the above
-
saves program development time
-
code reusability
-
data hiding
-
A and B
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.
-
Extraction Operator
-
Insertion Operator
-
Questionmark Colon operator
-
Scope resolution operator
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++.
-
C with structures
-
C with classes
-
C in addition to classes
-
C in addition to structures
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.
B
Correct answer
Explanation
You cannot have multiple main methods with the same signature in a class. While method overloading allows multiple main methods with different parameter lists, only main(String[] args) serves as the JVM entry point. This question implies identical signatures.
-
Security
-
Portability
-
Multiple Inheritance
-
Multi Level Inheritance
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.
-
Method & Interface Only
-
Encasulation
-
Database
-
None of the Above
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.