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. prints m1 method in C1 class

  2. prints m1 method in anonumous class

  3. compile time error

  4. Runtime error

  5. none of the above

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

The m1() method in c2 returns an anonymous subclass of c1 that overrides the m1() method. When ob1.m1() is called on this returned object, Java's dynamic dispatch invokes the overridden version in the anonymous class, printing 'm1 mehod in anonymous class' (note the typo 'mehod').

Multiple choice technology programming languages
  1. A B A

  2. A B A B

  3. B B

  4. A B

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

When instantiating B, constructors of A then B run, printing 'A' and 'B'. During deserialization, because superclass A is not serializable, its no-arg constructor is invoked, printing 'A' again, while serializable B's constructor is bypassed. This results in the sequence 'A B A'.

Multiple choice technology packaged enterprise solutions
  1. "$baseclass"
  2. "@baseclass"

  3. pegabaseclass

  4. pzBaseClass

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

In PegaRULES Process Commander (PRPC), @baseclass is the ultimate base class from which all other classes inherit. It contains standard properties, activities, and rules available to all applications. Other choices like $baseclass or pzBaseClass are syntactically or contextually incorrect.

Multiple choice technology packaged enterprise solutions
  1. Inherits from @baseclass

  2. Inherits from Work-

  3. Contains most of your business logic

  4. Is usually the same as a “bottom level” class

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

A Top-level Class in Pega PRPC inherits from @baseclass, which is the ultimate parent class in the Pega class hierarchy. Work- is for work objects (cases), not top-level classes. While top-level classes contain business logic, that's not what defines them as top-level. They are not the same as bottom-level classes, which are leaf nodes in the hierarchy.

Multiple choice technology programming languages
  1. True

  2. False

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

The String class in Java is declared final, meaning it cannot be extended or subclassed. This design choice ensures that String's immutability guarantees and thread-safety properties cannot be compromised through inheritance.

Multiple choice technology programming languages
  1. transient

  2. synchronized

  3. volatile

  4. abstract

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

The 'synchronized' keyword cannot be used with instance variables - it is used only with methods, blocks, or static methods to control thread access. The 'abstract' keyword is used for classes and methods, not instance variables. 'transient' and 'volatile' are valid modifiers for instance variables - transient prevents serialization, while volatile ensures visibility across threads.

Multiple choice technology programming languages
  1. class someclass extends mainclass

  2. protected class someclass extends mainclass

  3. public class someclass extends mainclass

  4. private class someclass extends mainclass

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

When writing a utility class that extends another class and will be used by multiple classes in different packages, it must be declared 'public' to be accessible outside its own package. 'protected' would only allow subclass access, 'private' would prevent any external access, and the default (package-private) wouldn't allow cross-package use.

Multiple choice technology programming languages
  1. class someclass extends mainclass

  2. protected class someclass extends mainclass

  3. public class someclass extends mainclass

  4. private class someclass extends mainclass

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

To make a Java class accessible to classes in different packages, the class must be declared as public. Default (package-private), protected, or private access modifiers would restrict visibility, preventing external packages from using it.

Multiple choice technology programming languages
  1. transient

  2. synchronized

  3. volatile

  4. abstract

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

Instance variables cannot use modifiers that apply to methods or classes. 'synchronized' is a method-level keyword for thread safety and 'abstract' applies to classes and methods. 'transient' and 'volatile' are valid instance variable modifiers for serialization and thread visibility respectively.

Multiple choice technology
  1. True

  2. False

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

In object-oriented systems like Documentum, an object is a single instance of an object type or class, not a 'multiple instance.' Object types define the structure, and multiple objects can be created from that type, but each individual object represents one instance of that type.

Multiple choice technology
  1. Persistent

  2. Non Persistent

  3. No objects are created

  4. type of object is not predictable

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

Non-persistent (transient) objects exist only during a session and are destroyed when the session terminates. These objects are created at runtime for temporary operations and are not stored in the database, making them ideal for short-lived processing needs.

Multiple choice technology programming languages
  1. Polymorphism

  2. Inheritance

  3. Name Mangling

  4. Function Signature

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

While function signatures define the overload, the compiler uses Name Mangling to generate unique names for functions with identical names but different signatures, allowing the linker to distinguish and resolve the calls correctly at runtime.