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

  2. False

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

Constructors are not inherited in C#. When you create a derived class, you must explicitly define constructors. The derived class can call the base class constructor using 'base()', but the constructors themselves are not inherited like other methods. This is a fundamental aspect of how C# handles object construction.

Multiple choice technology web technology
  1. System.Object

  2. System.Page

  3. System.Web

  4. System.Namespace

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

In .NET, System.Object is the ultimate base class from which all other classes derive. Every class in the .NET Framework, whether built-in or custom, inherits from System.Object either directly or through inheritance chains. This provides common methods like ToString(), Equals(), and GetHashCode() to all objects.

Multiple choice technology web technology
  1. True

  2. False

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

True is correct because these five are indeed the standard access specifiers in .NET (C# and VB.NET). Private restricts access to the containing class, Protected to derived classes, Public to any code, Internal to the same assembly, and Protected Internal to either derived classes or same assembly. These are the fundamental access modifiers for controlling member visibility.

Multiple choice technology web technology
  1. True

  2. False

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

False is correct because .NET supports many more class types beyond just these three. .NET includes partial classes (split across files), generic classes (with type parameters), abstract classes (cannot be instantiated), static classes (only static members), sealed classes (cannot be inherited), and regular concrete classes. The statement is too restrictive.

Multiple choice technology programming languages
  1. A

  2. AA

  3. Can't locate object method "foo" via package "A"

  4. none of the above

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

In Perl, the bareword construction NEW A acts as a method call A->NEW(). Inside AUTOLOAD, calling ref(shift) prints the reference package name A twice: first for the invalid method call foo(), and a second time when the object goes out of scope and triggers the DESTROY method.

Multiple choice technology programming languages
  1. True

  2. False

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

A->new('foo') passes 'A' as $class and 'foo' as $param (correct). new A('foo') also passes 'A' as $class and 'foo' as $param (correct). However, A::new('A', 'foo') is NOT equivalent - it bypasses Perl's inheritance mechanism and directly calls the subroutine, which fails if new() is inherited from a parent class. The third form is methodologically different.

Multiple choice technology programming languages
  1. interface

  2. class

  3. Object

  4. None of these

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

In Java Collections Framework, SortedMap is an interface that extends Map. It provides a total ordering on its keys. Classes like TreeMap implement this interface. Abstract classes and concrete classes exist, but SortedMap itself is an interface.

Multiple choice technology web technology
  1. Classes, Objects, Methods,Heritance,Capsulation and Multimorphism

  2. Classes,Dock Objects, Methods,Heritance,Encapsulation and Multimorphism

  3. Classes, Objects, Methods,Heritance,Capsulation and Polymorphism

  4. Classes, Objects, Methods, Inheritance, Encapsulation and Polymorphism

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

Option D correctly lists the four fundamental principles of Object-Oriented Programming: Classes (templates for objects), Objects (instances of classes), Methods (behaviors/functions), Inheritance (deriving properties from parent classes), Encapsulation (bundling data and methods), and Polymorphism (many forms/behaviors). Options A, B, and C contain typos ('Heritance', 'Capsulation', 'Dock Objects', 'Multimorphism') making them incorrect.

Multiple choice technology programming languages
  1. True

  2. False

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

JavaScript allows adding custom methods and properties to objects directly without using prototype. You can add properties to individual object instances (obj.customProp = 'value') or to constructor functions (Constructor.customMethod = function(){}). Prototype is used for inheritance shared across instances, but direct addition is also valid.

Multiple choice technology programming languages
  1. True

  2. False

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

You can add custom methods to built-in constructor prototypes (like String.prototype or Array.prototype), but not to Math which is a static object. However, the statement says 'like String, Math and others' - while String can be extended via prototype, Math cannot be extended the same way. More importantly, modifying built-in prototypes is generally considered bad practice and can cause conflicts.

Multiple choice technology programming languages
  1. this()

  2. super()

  3. both

  4. none of these

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

The this() keyword is used to call another constructor from within a constructor in the same class (constructor chaining). It must be the first statement in the constructor body. The super() keyword calls the parent class constructor, not a same-class constructor.

Multiple choice technology programming languages
  1. True

  2. False

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

Primitive data types cannot be directly serialized in Java - serialization works on objects. To serialize primitives, they must be wrapped in their corresponding wrapper classes (Integer, Double, etc.). The serialization mechanism operates on ObjectOutputStreams which write object graphs, not primitive values.