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 web technology
  1. HashMap is Interface and Map is class that implements that.

  2. Both are interfaces

  3. Map is Interface and Hashmap is class that implements that.

  4. None of the above

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

In Java, Map is an interface that defines the contract for key-value mappings, while HashMap is a specific class that implements the Map interface using a hash table.

Multiple choice technology programming languages
  1. Compilation error at line 5

  2. Compilation error at line 9

  3. Runtime exception at line 11

  4. None of these

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

The code compiles successfully. SubclassY extends SuperclassX (protected method, package-private field) from packageX.packageY - subclasses can access protected members. Line 5 is valid (polymorphism: SubclassY IS-A SuperclassX). Lines 9-11 access protected method and package-private field through a SubclassY reference, which is valid within the same package hierarchy. The code compiles and runs without errors, so 'None of these' (D) is correct.

Multiple choice technology web technology
  1. only pass by value

  2. only pass by reference

  3. supports both

  4. none of the above

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

Java always passes references by value - the reference itself is copied, but both copies point to the same object. This means modifications to the object are visible to the caller, but reassigning the reference is not. The 'pass by value' terminology refers to the reference copy, not the object.

Multiple choice technology web technology
  1. a. FilePathXmlApplicationContext class

  2. b. SystemXmlPathApplicationContext class

  3. c. FileSystemXmlApplicationContext class

  4. d. XmlFileApplicationContext class

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

The question text is missing ('1.)'), but based on the options about ApplicationContext implementations, FileSystemXmlApplicationContext (option C) is indeed a valid Spring ApplicationContext implementation that loads configuration from the file system.

Multiple choice technology web technology
  1. a. TransactionalTestExecutionListener class

  2. b. AbstractTransactionalSpringContextTests class

  3. c. TestExecutionListener class

  4. d. AbstractTestExecutionListener class

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

TransactionalTestExecutionListener is the TestContext framework class responsible for managing transactions in tests - it handles transaction creation, rollback for test isolation, and cleanup.

Multiple choice technology programming languages
  1. serialization support

  2. platform independent

  3. object diagnostic output

  4. run-time class information

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

CObject provides serialization support through the Serialize method, runtime class information via DECLARE_DYNAMIC/IMPLEMENT_DYNAMIC macros, and diagnostic dumping through Dump. Platform independence is not a feature - CObject is part of Windows-specific MFC.

Multiple choice technology programming languages
  1. Member Function

  2. Same name as Class name

  3. Default constructor initializes all non-initialized fields and variables to zero.

  4. Compiler adds an empty constructor, if we do not write our own constructor

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

Constructors are special member functions with the same name as their class. The default constructor initializes primitive fields to zero/null. If no constructor is written, the compiler provides a default constructor.