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. To get information about event-handler

  2. To get or set property values

  3. Classes in other namespace can use reflection to access data and to determine which fields to persist

  4. None of the above

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

Reflection can inspect event handlers, get/set property values dynamically, and allow cross-namespace access to type metadata. All these are valid capabilities of the System.Reflection namespace in .NET.

Multiple choice technology programming languages
  1. using System.Collections.Generic; Dictionary < string , StringBuilder >() dctobj = new Dictionary < string , StringBuilder >;

  2. using System.Collections.Generic; Dictionary < string , StringBuilder > dctobj = new Dictionary < string , StringBuilder >();

  3. using System.Collections.Generic; Dictionary < string , StringBuilder > dctobj = new Dictionary < string , StringBuilder >;

  4. using System.Text; Dictionary < string , StringBuilder > dctobj = new Dictionary < string , StringBuilder >();

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

Option B shows correct Dictionary initialization syntax with proper type parameters and parentheses for instantiation. Option A is missing instantiation parentheses. Option C is missing parentheses. Option D uses wrong namespace (System.Text for StringBuilder is fine, but Dictionary needs Collections.Generic).

Multiple choice technology programming languages
  1. Throwable

  2. Catchable

  3. Runable

  4. Problem

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

To solve this question, the user needs to know the hierarchy of Java exceptions and errors.

Both class Error and class Exception are children of the parent class Throwable. This means that any class that extends Throwable can be used to represent an error or an exception that occurs during the execution of a Java program.

Option A is correct because Throwable is the parent class of both Error and Exception.

Option B is incorrect because there is no class called Catchable in Java.

Option C is incorrect because Runnable is an interface in Java, not a class that represents an error or an exception.

Option D is incorrect because there is no class called Problem in Java that represents an error or an exception.

Therefore, the answer is: A

Multiple choice technology databases
  1. Only local or packaged sub programs can be overloaded.

  2. Overloading allows different functions with the same name that differ only in their return types.

  3. Overloading allows different subprograms with the same number, type and order of the parameter.

  4. Overloading allows different subprograms with the same name and same number or type of the parameters.

  5. Overloading allows different subprograms with the same name but different in either number or type or order of parameter.

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

Package overloading in PL/SQL allows multiple subprograms with the same name to coexist if they differ in their parameter signatures. Only local subprograms or packaged subprograms can be overloaded - standalone procedures cannot use overloading (A is true). Overloading requires that subprograms differ in the number, type, or order of parameters - having the same parameter signature is not allowed (E is true). Option B is false because overloading based solely on return type is not permitted. Option C is false because overloading requires differences in parameters. Option D is false because subprograms with identical parameters cannot be overloaded.

Multiple choice technology databases
  1. Packages can be nested.

  2. You can pass parameters to packages.

  3. A package is loaded into memory each time it is invoked.

  4. The contents of packages can be shared by many applications.

  5. You can achieve information hiding by making package constructs private.

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

PL/SQL packages cannot be nested, nor can they accept parameters directly (though their subprograms can). They are loaded into memory once, not on every invocation. The true statements are that package contents can be shared and information hiding is achieved by making constructs private.

Multiple choice technology databases
  1. True

  2. False

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

Identifiers defined only in the package body (not in the package specification) are PRIVATE constructs, not public. They are invisible outside the package body and can only be used by other subprograms within the same package body. To make identifiers public and visible outside the package, they must be declared in the package specification. Therefore, the statement in the question is false, making option B the correct answer.

Multiple choice technology programming languages
  1. True

  2. False

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

In exception handling hierarchies, a catch block can catch exceptions of its declared type or any subclass of that type due to polymorphism. If you catch Exception ( superclass), it will also catch IOException, SQLException, etc. (subclasses). This is a fundamental principle of polymorphic exception handling in object-oriented programming.

Multiple choice technology programming languages
  1. True

  2. False

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

In Java, a class cannot be both final and abstract because these modifiers have contradictory purposes. 'final' prevents inheritance (no subclasses allowed), while 'abstract' requires inheritance (must be subclassed to be instantiated). This creates an oxymoron - a class that both requires and forbids subclasses simultaneously. The compiler will reject this combination.

Multiple choice technology programming languages
  1. True

  2. False

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

Abstract classes can and often do have constructors. Although you cannot instantiate an abstract class directly, its constructor is called when a concrete subclass is instantiated using super() in the subclass constructor. This is useful for initializing fields defined in the abstract class that are common to all subclasses. The constructor executes before the subclass constructor's code.

Multiple choice technology programming languages
  1. True

  2. False

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

In Java, a method with no access modifier (package-private) can indeed be overridden by a method marked protected. This is valid because protected provides broader access than package-private, allowing subclasses (even in different packages) to access the method. The Liskov substitution principle permits widening access visibility in overriding methods.