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. If assertions are not enabled at run time it prints an error message.

  2. If assertions are not enabled at run time it prints nothing.

  3. With assertions enabled it prints an error message.

  4. With assertions enabled it prints nothing.

  5. The assert statement is being used to check a class invariant--something that must be true about each instance of the class

  6. The assert statements are being used to check a precondition--something that must be true when the method is invoked.

Reveal answer Fill a bubble to check yourself
B,D,E Correct answer
Explanation

If assertions are disabled, assert statements are ignored, printing nothing. With assertions enabled, the constructor and setter calls succeed because the invariant c > a + 2 * b holds (e.g., 251 > 50 + 200 is true), so nothing is printed. The assertions check a class invariant.

Multiple choice technology programming languages
  1. vtable entry

  2. this pointer

  3. Constructors

  4. default value

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

The this pointer is a hidden pointer passed to non-static member functions that points to the object invoking the method. It allows the compiler to resolve which object's data members are being accessed when multiple objects of the same class exist.

Multiple choice technology programming languages
  1. True

  2. False

  3. Neither true nor false

  4. No idea

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

In Java, all variables declared in an interface are implicitly public, static, and final - they are constants by design. Abstract classes, however, can contain both final constants and non-final instance variables, giving them more flexibility. The statement correctly captures this distinction.

Multiple choice technology programming languages
  1. A single copy of the data member exists

  2. The data member is initialised to zero before the first object is created

  3. Requires a global definition

  4. Storage is allocated to the static data member on declaration

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

Static data members are declared in the class but storage is NOT allocated at declaration - only at definition outside the class. This makes option D the false statement. The other options correctly describe static member behavior.

Multiple choice technology platforms and products
  1. A public class which contains a main method with proper signature (Arguments, return types etc).

  2. We can run any classes

  3. Only those classes which have public no argument constructors.

  4. None of these

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

To run a Java class directly from the Package Explorer, the class must contain a standard main method with the correct signature (public static void main(String[] args)). Other classes without this entry point cannot be executed directly as standalone applications.

Multiple choice technology
  1. Before Obj-Open, the step page has to be created using Page-New

  2. The step page can be classless if it is temporary

  3. An instance of a step page with the same name can be reused and the data must be cleared using Page-Reset

  4. An instance of step page with the same name can be reused and the data is cleared automatically.

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

When Obj-Open is called, if a step page with the same name already exists, it will reuse that page. Pega automatically clears the existing data on that page before loading the new instance - you don't need to manually call Page-Reset. The step page doesn't need to be created beforehand.

Multiple choice technology web technology
  1. Implements java.io.Serializable

  2. Override equals() method

  3. Override hashCode() method

  4. Both a, b and c

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

Component classes require implementing Serializable for persistence/caching, and must override equals() and hashCode() for proper behavior in collections and as cache keys. All three requirements are mandatory for component classes in frameworks like Hibernate.

Multiple choice technology web technology
  1. Transient, persistent, destroyed

  2. Transient, stored, detached

  3. Transient, persistent, detached

  4. open, close, detached

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

Hibernate defines three states for persistent classes: transient (not associated with any session, no database row), persistent (associated with a session and has a database identity), and detached (formerly persistent but no longer associated with a session, still has database identity).

Multiple choice technology web technology
  1. Override equals() method

  2. Override hashCode() method

  3. Both a and b

  4. Neither a nor b

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

Java's Set implementations rely on both equals() and hashCode() to determine uniqueness and prevent duplicates. When storing persistent objects in a Set, you must override both methods to ensure correct behavior during add/contains operations.

Multiple choice technology web technology
  1. In classes that implement IEnumerable, the collection is not serialized

  2. You cannot serialize an object's public fields.

  3. You cannot serialize XmlNode object

  4. It does not serialize type information.

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

XML serialization in .NET cannot serialize type information, which means polymorphic behavior is lost during serialization. When an object is serialized and then deserialized, it may not retain its original runtime type. This is a key limitation compared to binary serialization.

Multiple choice technology web technology
  1. Delegation

  2. Composition

  3. Polymorphism

  4. Inheritance

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

The code demonstrates Composition - a 'has-a' relationship between classes. Car contains an Engine object (myEngine), and Engine contains an array of Piston objects (myPistons). This is object composition, not inheritance (is-a relationship), delegation (forwarding calls), or polymorphism (same interface different implementations).