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. A class that is abstract may not be instantiated.

  2. The final keyword indicates that the body of a method is to be found elsewhere. The code is written in non-Java language, typically in C/C++.

  3. A static variable indicates there is only one copy of that variable.

  4. A method defined as private indicates that it is accessible to all other classes in the same package.

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

An abstract class cannot be instantiated directly, and a static variable has only one copy shared across all instances of a class. The final keyword does not mean a method is implemented elsewhere (that is native), and private restricts access to the defining class only.

Multiple choice technology programming languages
  1. stdio.h

  2. iomanip.h

  3. afcapp.h

  4. afxwin.h

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

afxwin.h is the core MFC header that declares fundamental classes like CWnd, CWinApp, and CDocument. It's automatically included in MFC projects and contains the base class hierarchy for Windows applications. stdio.h is for C I/O, iomanip.h for C++ I/O formatting, and afcapp.h doesn't exist.

Multiple choice technology programming languages
  1. CWnd class

  2. CWinApp class

  3. CWinThread class

  4. None of the above

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

CWinApp encapsulates the WinMain() functionality in MFC applications - it initializes the application, processes the message loop, and handles cleanup. Each MFC app has exactly one CWinApp-derived object. CWnd handles window functionality, CWinThread manages threads, and CWinApp actually contains the application's entry point logic.

Multiple choice technology platforms and products
  1. Extension methods

  2. Lambda Expression

  3. Abstract methods

  4. Expression trees

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

Extension methods, introduced in C# 3.0, allow adding methods to existing compiled classes without using inheritance or modifying the original class. They are static methods with special syntax that appear as instance methods of the extended type. Lambda expressions, abstract methods, and expression trees serve different purposes.

Multiple choice technology programming languages
  1. public

  2. private

  3. friendly

  4. transient

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

public and private are access modifiers controlling class member visibility. transient is a field modifier indicating a variable should not be serialized. 'friendly' is not a Java modifier - the default (package-private) access has no keyword.

Multiple choice technology programming languages
  1. to get to access hardware that Java does not know about

  2. to define a new data type such as an unsigned integer

  3. to write optimised code for performance in a language such as C/C++

  4. to overcome the limitation of the private scope of the method

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

Native methods are declared in Java but implemented in platform-specific languages like C or C++. This is done to access low-level hardware features or to optimize performance-critical code.

Multiple choice technology programming languages
  1. SortedMap

  2. Tree

  3. Set

  4. SortedSet

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

To solve this question, the user needs to know what the TreeMap class is used for and which collection interface it implements.

The TreeMap class in Java is used to implement a map interface that sorts the keys in natural order. It provides an efficient means of storing key/value pairs in sorted order, making it useful for scenarios where you need to perform operations such as lookups, insertions, and deletions in a sorted collection.

Now, let's go through each option and explain why it is right or wrong:

A. SortedMap: This option is correct. TreeMap implements the SortedMap interface, which extends the Map interface and provides additional methods for retrieving and manipulating elements in a sorted order.

B. Tree: This option is incorrect. While TreeMap is implemented using a tree structure, it does not directly implement the Tree interface.

C. Set: This option is incorrect. TreeMap does not implement the Set interface, which is used for collections of unique elements.

D. SortedSet: This option is incorrect. TreeMap does not implement the SortedSet interface, which is used for sorted collections of unique elements.

The Answer is: A

Multiple choice technology programming languages
  1. Shadowing

  2. Late Binding

  3. .NET Reflection

  4. All of the above

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

Shadowing (using the Shadows keyword in VB.NET) redefines an inherited member with the same name in a derived class without overriding it, completely replacing the base class member's signature and implementation.

Multiple choice technology testing
  1. True

  2. False

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

SetTOProperty changes the property values of a test object dynamically during the run-time session only. It does not permanently modify or save these changes to the Object Repository on disk, making the statement false.

Multiple choice technology testing
  1. CreatePage = New Pages

  2. New CreatePage = Pages()

  3. Set CreatePage = New Pages

  4. Dim CreatePage = New Pages

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

VBScript requires the 'Set' keyword when assigning object references. The correct syntax is 'Set CreatePage = New Pages'. Options A and B use incorrect syntax without Set or with wrong keyword order, and Dim cannot be combined with New in the same statement.

Multiple choice technology programming languages
  1. True

  2. False

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

C# does not support multiple inheritance with classes - a class can only inherit from one base class. However, C# does support multiple inheritance through interfaces (a class can implement multiple interfaces). The statement refers to class inheritance, which is not supported.

Multiple choice technology programming languages
  1. Value

  2. Default

  3. Object

  4. Param

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

In C# and VB.NET, the implicit parameter name in a property setter is 'value'. When you write set { _field = value; }, 'value' automatically contains the value being assigned to the property. This is a language-defined implicit parameter name that you don't declare - it's available by default within the set accessor.