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 platforms and products
  1. Code-Pega-List

  2. Rule-Pega-Obj

  3. pxResults

  4. The same class as the returned instance

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

In Pega, the Obj-List method creates a top-level clipboard page of class Code-Pega-List to hold the search results. The actual instances returned by the query are stored inside the pxResults page list embedded within this Code-Pega-List page.

Multiple choice technology programming languages
  1. ) A static method may override another static method

  2. A static method cannot override a non-static method

  3. non-static method cannot override a static method

  4. A non-static method may be overloaded by a static method

  5. A synchronized method cannot be overridden

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

Option A is incorrect because static methods are hidden (not overridden) in subclasses - a static method in a subclass with the same signature hides the parent's static method. Option B is correct - a static method cannot override a non-static method because they belong to different scopes (class vs instance). Option C is correct - a non-static method cannot override a static method for the same reason. Option D is correct - method overloading is valid between static and non-static methods since they have different signatures (static vs instance context). Option E is incorrect - synchronized methods can be overridden; synchronization is an implementation detail, not a contract restriction.

Multiple choice technology programming languages
  1. depth must be an int

  2. dive must be a method.

  3. dive must be the name of an instance field.

  4. submarine must be the name of a class

  5. submarine must be a method.

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

The statement submarine.dive(depth) uses dot notation, which in Java can represent: 1) A method call: object.method() 2) Field access: object.field 3) Nested class access: Outer.Inner 4) Enum constant access. In this context, 'dive' followed by parentheses with an argument 'depth' indicates a method invocation. This is the only certainty - dive is definitely a method. We cannot be certain about 'depth' (it could be int, long, Integer, etc., depending on the method signature), nor about 'submarine' (it could be a variable of any type, not necessarily a class name).

Multiple choice technology programming languages
  1. Exception

  2. A Exception

  3. A Exception B

  4. A B Exception

  5. Compilation fails because of an error in line 14.

  6. Compilation fails because of an error in line 19.

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

The code uses polymorphism to call B's process method. It runs super.process() to print 'A ', then throws a RuntimeException which is caught in main and prints 'Exception '. Unreachable code compile errors do not trigger for statements after an if(true) throw statement.

Multiple choice technology programming languages
  1. System.gc();

  2. Runtime.gc();

  3. System.freeMemory();

  4. Runtime.getRuntime().growHeap();

  5. Runtime.getRuntime().freeMemory();

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

System.gc() is a method that suggests to the Java Virtual Machine that it would be advantageous to run the garbage collector. The JVM may choose to ignore this suggestion, but it's the standard way to programmatically request GC effort. The other options are incorrect: Runtime.gc() does not exist (gc() is a method on Runtime, but you need Runtime.getRuntime().gc()), System.freeMemory() does not exist, and Runtime.getRuntime().growHeap() and Runtime.getRuntime().freeMemory() are not standard Java methods.

Multiple choice technology platforms and products
  1. Rule-File-Binary.

  2. Rule-File-Text

  3. Rule-Obj-Binary

  4. Rule-Obj-Text

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

Rule-File-Binary is the Pega rule type designed to store binary file content, including images like JPG, JPEG files, GIFs, and other non-text files. Rule-File-Text stores text-based files, while Rule-Obj-Binary and Rule-Obj-Text are not valid Pega rule class names for file storage purposes.

Multiple choice technology platforms and products
  1. Code-Pega-List

  2. Rule-Pega-Obj

  3. pxResults

  4. The same class as the returned instance

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

The Obj-List method creates a top-level clipboard page with class Code-Pega-List. This is a system class specifically designed to hold list results generated by the Obj-List method. Rule-Pega-Obj is for object rules, pxResults is a property name within the list page, and the class is not determined by the returned instance type.

Multiple choice technology programming languages
  1. Car

  2. Ford

  3. Dodge

  4. Wheels

  5. Vehicle

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

Car implements Serializable, so its subclass Ford is also serializable. However, Dodge contains a non-serializable field w (Wheels is not serializable) without being marked transient, so serializing Dodge instances will throw a NotSerializableException.

Multiple choice technology programming languages
  1. 1 2

  2. 2 2

  3. 2 3

  4. Compilation fails

  5. Exception occurs at runtime

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

TreeSet fails because the Dog class doesn't implement Comparable interface and no Comparator is provided. When TreeSet tries to insert Dog objects, it needs to compare them for ordering, which requires either Comparable implementation or a custom Comparator. Since Dog doesn't implement Comparable, it throws ClassCastException at runtime when attempting to cast Dog to Comparable for comparison.

Multiple choice technology databases
  1. The return type for a method can be any Java type, including void

  2. An important principal of object oriented programming is implementation hiding

  3. When you perform mathematical calculations on the unlike data type, java will perform a implicit conversion to unify the types

  4. All the Above

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

All three listed statements are true: Java method return types can be any type or void; implementation hiding is a key OOP concept (encapsulation); and Java performs implicit numeric promotions when operating on different numeric types.

Multiple choice technology databases
  1. .NET 2.0 and above

  2. .NET 3.0 and above

  3. .NET 3.5 and above

  4. .NET 4.0

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

Generics were introduced to the .NET Framework and C# language in version 2.0. Consequently, all subsequent versions (3.0, 3.5, 4.0, and newer) support generics as they build upon the CLR version 2.0 base. Therefore, ".NET 2.0 and above" is the correct starting point.

Multiple choice technology databases
  1. Class MyDictionary Implements Dictionary(Of String, String)

  2. Class MyDictionary Inherits HashTable

  3. Class MyDictionary Implements IDictionary

  4. Class MyDictionary End Class Dim t As New Dictionary(Of String, String) Dim dict As MyDictionary = CType(t, MyDictionary)

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

Using 'Implements Dictionary(Of String, String)' creates a type-safe dictionary in .NET. Generic Dictionary with specific type parameters ensures compile-time type checking. HashTable is not type-safe (stores Object), and the non-generic IDictionary interface also allows type violations.

Multiple choice technology databases
  1. Hashtable

  2. ArrayList

  3. Stack

  4. Heap

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

In VB.NET, Hashtable, ArrayList, and Stack are all collection types designed to store and manage groups of objects. Heap is a memory structure used by the runtime for memory management, not a collection class in the System.Collections namespace.

Multiple choice technology databases
  1. out is a PrintStream object

  2. Java support pointers

  3. AWT components are heavy-weight

  4. An abstract class has to be sub-classed

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

Java intentionally does NOT support pointers to eliminate entire classes of bugs (dangling pointers, memory leaks, unsafe access). Java uses references instead, which are safer because they can't point to arbitrary memory addresses. The 'out' object in System.out is a PrintStream. AWT components are heavy-weight (peer-based). Abstract classes must be sub-classed to be instantiated.