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. 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
B Correct answer
Explanation

A good hashCode implementation should combine significant fields using non-zero multipliers and handle null checks or existing field hashes appropriately. Option B combines the hash of the name string with the age field multiplied by a prime number, fulfilling standard contract requirements.

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.

Multiple choice technology programming languages
  1. MyOuter.MyInner m = new MyOuter.MyInner();

  2. MyOuter.MyInner mi = new MyInner();

  3. MyOuter m = new MyOuter();

  4. MyInner mi = new MyOuter.MyInner();

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

To instantiate a static nested class from outside its enclosing class, you must qualify the nested class name with the outer class name, using the syntax Outer.Inner obj = new Outer.Inner(). Other options fail due to missing qualifiers.

Multiple choice technology programming languages
  1. True

  2. False

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

Properties can be overridden polymorphically using keywords like virtual (in base class) and override (in derived class). These modifiers apply to the entire property declaration, not to individual accessors.

Multiple choice technology programming languages
  1. True

  2. False

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

In C# and similar languages, a property getter must return a value (cannot be void) because it needs to provide the property's value when accessed. The setter can be void since it just modifies state. This question specifically addresses the getter's return requirement.