Computer Knowledge

Object-Oriented Programming

2,239 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. Parent

  2. Child

  3. Both

  4. None of these

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

Static methods are bound at compile time based on reference type, not actual object type. Parent p = new Child(); p.staticMethod() calls Parent's version. This is because static methods belong to the class, not instances.

Multiple choice technology programming languages
  1. return type should be different

  2. access speciifer should be different

  3. arguments should be different

  4. the overloaded methods should throw a different excpetion

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

Method overloading requires different parameter lists (type, count, or order). Return type, access specifier, and exception throws alone don't distinguish overloaded methods - the compiler would see them as duplicate methods.

Multiple choice technology programming languages
  1. Overriding method can not throw more generic exception than base method

  2. Overriding method can throw new or broader checked exceptions

  3. None of the above

  4. Both a and b

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

In Java, an overriding method in a subclass cannot throw broader or more generic checked exceptions than the overridden method in the superclass. Doing so violates the Liskov Substitution Principle and causes a compilation error.

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.