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
-
Overloading
-
Overriding
-
Both 1 and 2
-
Dynamic polymorphism
A
Correct answer
Explanation
The println method in Java exhibits overloading because there are multiple versions of println that accept different parameter types (int, String, boolean, etc.), all sharing the same name but different signatures. Overriding requires inheritance and redefining a method in a subclass, which is not what println demonstrates.
-
Shared
-
Local
-
Both
-
None of the above
B
Correct answer
Explanation
Local object repository is simplest for basic record-and-run scenarios because it stores objects within the test itself, eliminating the need to manage external repository files. Shared repositories require more setup and maintenance coordination across multiple tests. The 'Both' option is misleading because using both types simultaneously would actually add complexity rather than simplify.
-
Overload
-
Load
-
Both A&B
-
None of the above
B
Correct answer
Explanation
The Load() method is specifically designed to load object repository files into memory for use during test execution. This method belongs to the ObjectRepositoryUtil object and accepts the file path as a parameter. The 'Overload' option is not a standard method for this purpose in QTP.
-
class aclass : public superclass
-
class aclass inherit superclass
-
class aclass <-superclass
-
None of the Above
A
Correct answer
Explanation
In C++, public inheritance is declared using a colon followed by the 'public' keyword and the base class name. Option A shows the correct syntax: 'class aclass : public superclass'. Options B and C use incorrect syntax not valid in C++.
-
class aClass{public:int x;};
-
/* A comment */
-
char x=12;
-
None of the Above
A
Correct answer
Explanation
The syntax class aClass { public: int x; }; is valid C++ for declaring a class with a public member. Option B is just a comment. Option C declares a variable, not a class definition. Therefore A is correct.
-
Constructor
-
Destructor
-
Constitutor
-
None of the Above
-
class aclass : public superclass
-
class aclass inherit superclass
-
class aclass <-superclass
-
None of the Above
-
class aClass{public:int x;};
-
/* A comment */
-
char x=12;
-
None of the Above
-
Constructor
-
Destructor
-
Constitutor
-
None of the Above
-
Constructor
-
Destructor
-
Constitutor
-
None of the Above
A
Correct answer
Explanation
A constructor is a special member function that initializes the data members of a class. It has the same name as the class and is automatically called when an object is created. Destructors clean up resources when objects are destroyed, and 'Constitutor' is not a valid C++ term.
-
class aclass : public superclass
-
class aclass inherit superclass
-
class aclass <-superclass
-
None of the Above
A
Correct answer
Explanation
C++ uses colon syntax for inheritance: 'class DerivedClass : accessSpecifier BaseClass'. Options B and C show incorrect syntax ('inherit' keyword and '<-' notation are not valid in C++).
-
A. return super.hashCode();
-
B. return name.hashCode() + age * 7;
-
C. return name.hashCode() + comment.hashCode() / 2;
-
D. return name.hashCode() + comment.hashCode() / 2 - age * 3;
-
Copy DML
-
Propagate from Neighbors
-
Propagate from other component
-
All of the above
B,C
Correct answer
Explanation
In Ab Initio, DML (Data Manipulation Language) can be copied from other components through propagation. 'Propagate from Neighbors' copies from connected components in the graph, while 'Propagate from other component' allows selecting any component. 'Copy DML' is not a standard propagation method, and 'All of the above' would be incorrect since option A is wrong.
-
shared
-
private
-
public
-
protected
B
Correct answer
Explanation
In .NET, assemblies are private by default, meaning they are only accessible within the application directory where they are deployed. Public or shared assemblies must be explicitly configured in the Global Assembly Cache (GAC).
-
The program will not compile.
-
The program will compile but will throw run-time exception.
-
The statement 'X' manifests that objects of type Instrument as well as sub-types can be added to the list 'allInstruments'.
-
It is not possible to add any type of objects to the list 'allInstruments'.
A
Correct answer
Explanation
The wildcard ? extends Instrument means the list can hold any subtype of Instrument, but the compiler cannot guarantee type safety for add operations. You can only add null to such a list because the actual type could be any specific subclass (like Guitar or Violin), and adding the wrong subtype would break type safety. The code attempts to add Guitar and Violin objects, which causes a compilation error.