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

  2. False

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

The prototype property is the standard, supported way to add methods to constructor functions in JavaScript. Without using prototype, you can only add methods to individual object instances, not to the object type/class itself. The statement is fundamentally incorrect.

Multiple choice technology web technology
  1. Window class

  2. Web class

  3. Form class

  4. Page class

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

To solve this question, the user needs to have knowledge about the basic concepts of web forms and their inheritance in ASP.NET.

The correct answer is:

The Answer is: D

Explanation:

All web forms in ASP.NET inherit from the Page class. This class provides a set of methods, properties, and events that are used to build and interact with web pages. The Page class is defined in the System.Web.UI namespace, and it is the base class for all web forms in ASP.NET. The Page class provides a number of important features, such as the ability to handle user input, display dynamic content, and manage state information. Therefore, option D is the correct answer.

Option A is incorrect because the Window class is not related to web forms in ASP.NET.

Option B is also incorrect because there is no such thing as a Web class in ASP.NET.

Option C is incorrect because the Form class is not the base class for web forms in ASP.NET. It is used to create Windows Forms applications, not web forms.

Multiple choice technology programming languages
  1. Implements

  2. public

  3. delegate

  4. if

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

In C#, 'Implements' is not a keyword. The correct keyword for interface implementation is implicit through the class declaration or explicit using the interface name in C# syntax. 'public', 'delegate', and 'if' are all valid C# keywords - public is an access modifier, delegate defines a delegate type, and if is a conditional statement.

Multiple choice technology programming languages
  1. Public

  2. Private

  3. Protected

  4. Internal

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

In C#, top-level classes (classes not nested within other classes) default to internal accessibility if no access modifier is specified. They can only be declared as public or internal, and cannot be declared as private or protected at the namespace level.

Multiple choice technology programming languages
  1. Access is limited to the current assembly.

  2. Access is limited to the containing class or types derived from the containing class.

  3. Access is limited to the containing type

  4. Access is limited to the current assembly or types derived from the containing class

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

The 'protected internal' modifier restricts access to the current assembly OR to types derived from the containing class in another assembly. Other options incorrectly restrict access solely to the assembly or solely to derived/containing types.

Multiple choice technology programming languages
  1. true

  2. false

  3. an exception is thrown

  4. None of these

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

Unboxing converts a reference type back to a value type. If the reference type is null (unboxing a null object reference to a value type), C# throws a NullReferenceException - you cannot unbox null to a value type like int. The operation doesn't return null (value types can't be null unless nullable), nor does it return false (which isn't applicable to the unboxing operation itself).

Multiple choice technology platforms and products
  1. Static-Implemented

  2. Implicit

  3. Explicit

  4. Auto-implemented

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

Auto-implemented properties, introduced in C# 3.0, enable you to quickly define a property without writing explicit get and set logic. The compiler automatically generates the backing field and getter/setter methods. Syntax is 'public int Property { get; set; }' - reducing boilerplate code.

Multiple choice technology programming languages
  1. Shared Methods

  2. Instance Methods

  3. Both A & B

  4. None of the above

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

VB.NET delegates can refer to both shared (static) methods and instance methods. When a delegate points to an instance method, it captures both the method and the target object. When pointing to a shared method, only the method is needed. Delegates are versatile and support both types.

Multiple choice technology web technology
  1. True

  2. False

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

Transfer Objects (also called Value Objects) are used to transfer data across tiers. While they often implement Serializable for network transmission in Java EE environments, it's not strictly mandatory. Other serialization mechanisms (XML, JSON, custom protocols) can be used. The interface is a practical requirement for RMI/IIOP but not a theoretical necessity for the pattern itself.

Multiple choice technology
  1. A file that contains a section of compiled Java code which, with other class files, can be used to run a Java

  2. A file that contains a set of security rules to ensure that Java can't be used to distribute viruses

  3. A file that is written by trainees on our courses

  4. A file that contains a library of methods and objects

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

A .class file contains compiled Java bytecode for a single class. Multiple class files work together (along with libraries) to run a complete Java application.

Multiple choice technology
  1. creating a subclass

  2. creating extra instances of the class

  3. allocating more memory to the class

  4. making a class more generic

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

When you extend a class using inheritance, you create a subclass (derived class) that inherits features from the superclass. The subclass is a specialized version of the parent class. Options B, C, and D describe unrelated concepts - extension is about inheritance, not instances or memory allocation.

Multiple choice technology programming languages
  1. public

  2. default

  3. static

  4. final

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

Variables declared in an interface are implicitly public, static, and final. They must be initialized as they become constants. Interface variables cannot have other access modifiers or be instance variables. Option B is incorrect - 'default' is not an explicit access modifier for interface variables.

Multiple choice technology testing
  1. A set of test cases for testing classes of objects

  2. An input or output range of values such that only one value in the range becomes a test case

  3. An input or output range of values such that each value in the range becomes a test case

  4. An input or output range of values such that every tenth value in the range becomes a test case.

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

An equivalence partition groups input values that are expected to produce similar results, so testing one value from the group is sufficient to represent the entire partition. This is the core principle of equivalence partitioning - one value represents the whole range.