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 programming languages
  1. Overloading

  2. Overriding

  3. Both 1 and 2

  4. Dynamic polymorphism

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology testing
  1. Shared

  2. Local

  3. Both

  4. None of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology testing
  1. Overload

  2. Load

  3. Both A&B

  4. None of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. class aclass : public superclass

  2. class aclass inherit superclass

  3. class aclass <-superclass

  4. None of the Above

Reveal answer Fill a bubble to check yourself
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++.

Multiple choice technology programming languages
  1. class aClass{public:int x;};

  2. /* A comment */

  3. char x=12;

  4. None of the Above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. Constructor

  2. Destructor

  3. Constitutor

  4. None of the Above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. class aclass : public superclass

  2. class aclass inherit superclass

  3. class aclass <-superclass

  4. None of the Above

Reveal answer Fill a bubble to check yourself
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++).

Multiple choice technology programming languages
  1. A. return super.hashCode();

  2. B. return name.hashCode() + age * 7;

  3. C. return name.hashCode() + comment.hashCode() / 2;

  4. D. return name.hashCode() + comment.hashCode() / 2 - age * 3;

Reveal answer Fill a bubble to check yourself
A Correct answer
Multiple choice technology
  1. Copy DML

  2. Propagate from Neighbors

  3. Propagate from other component

  4. All of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology web technology
  1. shared

  2. private

  3. public

  4. protected

Reveal answer Fill a bubble to check yourself
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).

Multiple choice technology programming languages
  1. The program will not compile.

  2. The program will compile but will throw run-time exception.

  3. The statement 'X' manifests that objects of type Instrument as well as sub-types can be added to the list 'allInstruments'.

  4. It is not possible to add any type of objects to the list 'allInstruments'.

Reveal answer Fill a bubble to check yourself
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.