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 java
  1. The class is fully encapsulated

  2. The code demonstrates polymorphism

  3. The ownerName variable breaks encapsulation

  4. The cardID and limit variables break polymorphism

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

Proper encapsulation requires all fields to be private with controlled access through methods. The ownerName field is public, breaking encapsulation. CardID and limit are correctly private. Option A is wrong (not fully encapsulated). Option B is wrong (no polymorphism shown). Option D is wrong (private fields don't break polymorphism).

Multiple choice technology programming languages
  1. The class is fully encapsulated

  2. The code demonstrates polymorphism

  3. The ownerName variable breaks encapsulation

  4. The cardID and limit variables break polymorphism

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

Proper encapsulation requires all fields to be private with access controlled through getters and setters. The ownerName field is declared public, allowing direct external access and modification - this breaks encapsulation regardless of the setter method's presence.

Multiple choice technology platforms and products
  1. MapView

  2. MapActivity

  3. MapController

  4. LocationOverlay

  5. None of above

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

MapView is the Android widget class that displays the actual map tiles and provides the visual map surface. MapActivity is the Activity base class for hosting maps, MapController provides programmatic control over the map, and Overlay allows drawing on top of the map. MapView is the correct answer for the View that displays the map.

Multiple choice technology platforms and products
  1. LocationProvider

  2. LocationManager

  3. LocationListener

  4. None of above

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

LocationProvider is the abstract superclass for all location providers (GPS, Network, Passive) that deliver location information. It defines the common interface and behavior that specific provider implementations must follow.

Multiple choice technology platforms and products
  1. Presentation

  2. Inheritance

  3. Polymorphism

  4. Abstraction

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

ORM (Object-Relational Mapping) is primarily a technique for Abstraction. It abstracts away the details of database interactions, allowing developers to work with objects in their programming language instead of writing raw SQL queries. While ORM techniques may leverage inheritance and polymorphism internally, their fundamental purpose is providing an abstraction layer between object-oriented code and relational databases.

Multiple choice technology platforms and products
  1. System.Data.Entity

  2. System.Data.Objects

  3. System.Objects.Data

  4. System.Entity.Data

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

The ObjectContext class belongs to the System.Data.Entity assembly in the Entity Framework. This assembly contains the core Entity Framework types including ObjectContext, EntityObject, and other fundamental classes. While ObjectContext works with objects conceptually, its actual implementation resides in System.Data.Entity.dll, not in System.Data.Objects or similarly named assemblies.

Multiple choice technology programming languages
  1. Salary

  2. Sport

  3. Athlete

  4. Team

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

Athlete (Option C) is the logical abstract base class for footballPlayer - a football player is a type of athlete. This follows the 'is-a' relationship principle of inheritance. Options A and D represent properties or associations, not inheritance relationships. Option B (Sport) would be a category the player participates in, not their base class.

Multiple choice technology programming languages
  1. No

  2. Yes, but only if the two classes have the same name

  3. Yes, but only if the main program does not declare both kinds

  4. Yes, this is always allowed

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

Yes, class definitions establish independent namespaces and scopes. Two entirely different classes are fully allowed to declare member functions with the exact same name and signature without causing compiler conflicts. This is a fundamental aspect of encapsulation and object-oriented design.

Multiple choice technology programming languages
  1. Inherits data members and member functions from base class

  2. Inherits constructors and destructor

  3. Object can access protected members with the dot operator

  4. Inherits data members and member functions from base class as well as Inherits constructors and destructor

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

A derived class inherits all data members and member functions from its base class, except constructors and destructor. This is the fundamental mechanism of inheritance in object-oriented programming. The inheritance creates an 'is-a' relationship where the derived class extends the base class functionality.

Multiple choice technology programming languages
  1. Polymorphism

  2. Inheritance

  3. Overloading

  4. None of these options

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

Inheritance represents an 'is-a' relationship between classes, where a derived class inherits properties from a base class. For example, a Car 'is a' Vehicle, so Car inherits from Vehicle. This is a core OOP concept that enables code reuse and hierarchical organization.

Multiple choice technology programming languages
  1. Zero instance

  2. Multiple instance

  3. Both Zero instance & Multiple instance

  4. None of these options

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

An abstract class is designed to be a base class that cannot be instantiated directly - it can have zero instances. The phrase 'cannot have multiple instance' is awkward phrasing but captures the same restriction. Abstract classes exist solely to be inherited from by concrete classes.

Multiple choice technology programming languages
  1. Serialization

  2. Persistence

  3. Marshalling

  4. None of these options

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

To solve this question, the user needs to understand the concept of object-oriented programming and the terminology used in it.

The state of an object refers to the values of its attributes or properties at a given point in time. Maintaining the state of an object means preserving these values so that they can be used later, even after the program has ended.

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

A. Serialization: Serialization refers to the process of converting an object into a format that can be stored or transmitted. While serialization can be used to maintain the state of an object, it is not the same thing as maintaining the state.

B. Persistence: This option is correct. Persistence refers to the act of preserving data beyond the lifetime of a program. In the context of object-oriented programming, persistence means maintaining the state of an object so that it can be used again later.

C. Marshalling: Marshalling is a technique used to transfer data between different applications or systems. While marshalling can be used to preserve the state of an object during transfer, it is not the same thing as maintaining the state.

D. None of these options: This option is incorrect because option B, Persistence, is the correct answer.

Therefore, The Answer is: B. Persistence.

Multiple choice technology programming languages
  1. Data hiding

  2. Encapsulation

  3. Data Binding

  4. None of these options

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

Encapsulation is the OOP principle of bundling data and methods that operate on that data within a single unit (class). It hides internal state and requires interaction through methods. Data hiding is a related concept about restricting access, while data binding is not a standard OOP term.