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

  2. False

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

In Java, both Error and Exception classes extend Throwable. Throwable is the root class of the exception hierarchy. Error represents serious unrecoverable errors (like OutOfMemoryError), while Exception represents recoverable conditions that applications should handle. Both inherit from Throwable.

Multiple choice technology programming languages
  1. True

  2. False

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

In Java, a lock can indeed be acquired on a Class object using synchronized blocks or static synchronized methods. Class-level locks are used to synchronize access to static methods or static data across all instances of the class. The lock is associated with the Class object itself, not with individual instances.

Multiple choice technology programming languages
  1. True

  2. False

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

Constructors are NOT inherited in Java. A subclass does not inherit constructors from its superclass. However, a subclass can call a superclass constructor using super() as its first statement. If no explicit constructor is defined in the subclass, the compiler generates a default no-arg constructor that calls super() implicitly.

Multiple choice technology programming languages
  1. FileWriter

  2. CharWriter

  3. Writer

  4. OutputStream

  5. FileOutputStream

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

Writer is the abstract superclass for all character stream classes that write characters. FileWriter, PrintWriter, BufferedWriter, and other character-writing classes all extend Writer. OutputStream is for byte streams, not character streams. CharWriter is not a standard Java class. FileOutputStream writes bytes, not characters.

Multiple choice technology programming languages
  1. True False True True True True

  2. True False False True True True

  3. True False True True True False

  4. True False True True False True

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

t1 and t3 are instances of tester, so instanceof tester is true for both, but false for t2 (which is a test). Since tester inherits from test, all three objects (t1, t2, and t3) are instances of test, making instanceof test true for all of them.

Multiple choice technology programming languages
  1. Root Tree Tree 15 15 15

  2. Root Tree Tree 10 15 15

  3. Root Tree Root 15 15 10

  4. Root Tree Tree 15 15 10

  5. Root Tree Tree 15 10 10

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

Calling r.get() prints Root. Calling t.get() and t1.get() invokes the overridden get() method in Tree, printing Tree and setting bark to 15. Since bark is inherited from Root and not shadowed in Tree, t.bark and t1.bark both print 15, while r.bark remains 10 as it was never modified.

Multiple choice technology testing
  1. Methods

  2. Functions

  3. Classes

  4. Parameters

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

When creating unit tests from source code, you select individual methods to test. Unit testing focuses on testing the smallest testable units - individual methods within a class - rather than entire classes or functions. You create test methods that verify specific method behaviors with different inputs.

Multiple choice technology operating systems
  1. Multiple inheritance from other classes

  2. Single inheritance from other classes

  3. No inheritance

  4. Only inherit interfaces

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

C# allows a class to inherit from only one base class (single inheritance), but it can implement multiple interfaces. This design avoids the diamond problem and complexity of multiple class inheritance while maintaining flexibility through interface implementation.

Multiple choice technology operating systems
  1. Microsoft

  2. MIcrosoft.Windows

  3. System.Object

  4. System.Windows

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

Every class in C# implicitly inherits from System.Object (or the object keyword alias), making it the universal base class. This provides common methods like ToString(), Equals(), and GetHashCode() to all objects in the .NET framework.

Multiple choice technology programming languages
  1. True

  2. False

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

In JavaScript, built-in objects like String and Math cannot have prototype extended in all environments. While some browsers allow it, it's not universally supported and is generally considered bad practice due to potential conflicts and pollution of shared prototypes.