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. static

  2. const

  3. extern

  4. none

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

In C++ class declarations, you cannot initialize static, const, or extern variables directly in the class declaration (with some exceptions for static const integral types in C++11 and later). The question states 'none' as correct, which is technically accurate for traditional C++ where these types require separate definition outside the class. However, modern C++ (C++11 and later) does allow inline initialization for static const members of integral types, and constexpr static members. The question appears to be testing older C++ rules.

Multiple choice technology programming languages
  1. "X extends Y" is correct if and only if X is a class and Y is an interface

  2. "X extends Y" is correct if and only if X is an interface and Y is a class

  3. "X extends Y" is correct if X and Y are either both classes or both interfaces

  4. "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces

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

In Java, the 'extends' keyword can only be used when both X and Y are classes (class inheritance), or when both X and Y are interfaces (interface inheritance). A class extends another class, and an interface extends another interface. A class implements an interface, not extends it.

Multiple choice technology packaged enterprise solutions
  1. Object-

  2. Work-

  3. @baseclass

  4. Data-

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

In Pega, class groups are directly inherited from @baseclass, which is the ultimate parent class in the Pega class hierarchy. All classes and class groups ultimately trace their inheritance back to @baseclass, making it the fundamental root of the class structure.

Multiple choice technology packaged enterprise solutions
  1. As a replacement for the Pega supplied Work- classes

  2. To contain specialized rules used by the application.

  3. As a temporary placeholder for a Pega purchased Framework

  4. To contain rules that will be used across the enterprise.

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

The framework class layer contains common, reusable rules designed to be shared and extended across the entire enterprise or multiple implementations. It does not replace Pega standard work classes, nor is it a temporary placeholder or intended solely for localized, specialized rules.

Multiple choice technology programming languages
  1. It can extend exactly one class and implement exactly one interface.

  2. It can extend exactly one class and can implement multiple interfaces.

  3. It can extend exactly one class or implement exactly one interface.

  4. It can implement multiple interfaces regardless of whether it also extends a class.

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

Anonymous inner classes can either extend one class OR implement one interface, but not both simultaneously. This is a syntax limitation - you cannot write 'new MyClass() implements MyInterface { }' or extend multiple classes.

Multiple choice technology programming languages
  1. Boo f = new Boo(24) { };

  2. Boo f = new Bar() { };

  3. Bar f = new Boo(String s) { };

  4. Boo f = new Boo.Bar(String s) { };

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

The correct syntax creates an anonymous subclass of Bar (which extends Boo). Option A is wrong because 24 is not a String. Option C is syntactically invalid. Option D is wrong syntax for anonymous class creation. Option B correctly instantiates Bar and makes it anonymous.

Multiple choice technology programming languages
  1. It must be marked final.

  2. It can be marked abstract.

  3. It can be marked public.

  4. It can be marked static.

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

Method-local inner classes CAN be marked abstract - they are defined inside a method like any other class and support abstract modifiers. They cannot be static (static inner classes are only class-level) and cannot be public (only default and private access are allowed for method-local classes).

Multiple choice technology programming languages
  1. Runnable r = new Runnable() { };

  2. Runnable r = new Runnable(public void run() { });

  3. Runnable r = new Runnable { public void run(){}};

  4. System.out.println(new Runnable() {public void run() { }});

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

This statement compiles because the anonymous inner class correctly implements the required run method of the Runnable interface. The other options fail due to syntax errors, such as missing parenthesis in option 3 or passing Java code as an argument in option 2, or missing implementation of the abstract run method in option 1.