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 databases
  1. SystemException

  2. ApplicationException

  3. Both (A) and (B)

  4. None of the Above

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

In Java EE and CORBA, user-defined application exceptions must extend ApplicationException (or a subclass thereof). SystemException is for system-level errors (transient failures, resource limits). The two hierarchies are separate - application exceptions for business logic errors, system exceptions for runtime failures.

Multiple choice technology databases
  1. public

  2. private

  3. synchronised

  4. native

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

Interface methods in Java are implicitly public and abstract. They cannot be declared as private, synchronized, or native - these modifiers are not allowed for interface method declarations. The access modifier for interface methods is always public, which matches the question's requirement.

Multiple choice technology programming languages
  1. x2.do2();

  2. (Y)x2.do2();

  3. ((Y)x2).do2();

  4. None of the above statements will compile

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

The reference x2 has compile-time type X but points to a Y object. Since do2() is only defined in Y, we must downcast x2 to Y before calling it. Option C correctly applies the cast before the method call with ((Y)x2).do2(). The extra parentheses ensure casting occurs first.

Multiple choice technology programming languages
  1. fa fa

  2. fa la

  3. la la

  4. Compilation fails

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

Static methods in Java are bound at compile-time based on the reference type, not the actual object type. The variable t has type Tenor, so t.sing() calls Tenor.sing() returning 'fa'. The variable s has type Singer, so s.sing() calls Singer.sing() returning 'la', despite s referencing a Tenor object.

Multiple choice technology programming languages
  1. h hn x

  2. hn x h

  3. b h hn x

  4. b hn x h

  5. bn x h hn x

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

The House(String) constructor calls this() to invoke House(), which implicitly calls super() to execute Building(). Building() prints 'b ', then House() prints 'h ', and finally House(String) prints 'hn x'. The complete output is 'b h hn x'.

Multiple choice technology programming languages
  1. Using NEW keyword

  2. Using CREATEOBJECT keyword

  3. Using GETOBJECT keyword

  4. Both A & B

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

In VB.NET, objects are instantiated using the 'New' keyword (e.g., 'Dim obj As New ClassName()'). CREATEOBJECT is used for COM objects (legacy VB6 compatibility) and GETOBJECT retrieves existing object references - neither is the standard .NET way.

Multiple choice technology programming languages
  1. Runtime Error

  2. Compiler Error

  3. Compiler Throws a warning message

  4. Both A & B

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

In VB.NET, if a derived class inherits a method and declares it with Public Overridable Sub F() instead of using the Overrides keyword, it implicitly hides the base member. This compiles but throws a warning message suggesting the use of the Shadows keyword.

Multiple choice technology programming languages
  1. Using NEW keyword

  2. Using CREATEOBJECT keyword

  3. Using GETOBJECT keyword

  4. Both A & B

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

In VB.NET, objects are instantiated using the NEW keyword. While CREATEOBJECT and GETOBJECT exist for COM/ActiveX interoperability, the standard way to create .NET objects is using NEW. Option D is incorrect because CREATEOBJECT is not for .NET objects.

Multiple choice technology testing
  1. The run-time or test object properties of any object in an open application.

  2. The test object properties and methods of any object in an open application.

  3. The run-time or test object properties and methods of any object in an open application.

  4. The run-time object properties and methods of any object in an open application.

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

Object Spy in QTP shows both runtime properties (actual values from the application) and test object properties (expected values) plus their available methods. Option A omits methods, B misses runtime properties, and D omits test object properties, making C the complete answer.

Multiple choice technology testing
  1. Run-Time Object

  2. Test Object

  3. Smart Identification Object

  4. Assistive Object

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

In UFT (Unified Functional Testing), the Object property is used to access the native Run-Time Object, which represents the actual application object being tested during test execution. This allows you to use methods and properties that belong to the real application object rather than UFT's test object abstraction. The Test Object is UFT's internal representation, while Run-Time Object gives you direct access to the application's native object.

Multiple choice technology programming languages
  1. Data Type

  2. Abstract Type

  3. User Defined Type

  4. All of these options

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

In object-oriented programming, a class is indeed a user-defined type that encapsulates data and behavior. Unlike primitive data types (int, float, char) which are built into the language, classes are defined by programmers to model real-world entities or abstract concepts. Classes combine data attributes and methods into a single reusable unit.

Multiple choice technology programming languages
  1. 57 22

  2. 45 38

  3. 45 57

  4. D. An exception occurs at runtime

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

An anonymous subclass of AbstractTest overrides getNum() to return 22. An anonymous subclass of AbstractTest.Bar overrides getNum() to return 57. The output f.getNum() + " " + t.getNum() prints 57 22.