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
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.
-
Window class
-
Web class
-
Form class
-
Page class
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.
-
Implements
-
public
-
delegate
-
if
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.
-
Public
-
Private
-
Protected
-
Internal
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.
-
Access is limited to the current assembly.
-
Access is limited to the containing class or types derived from the containing class.
-
Access is limited to the containing type
-
Access is limited to the current assembly or types derived from the containing class
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.
-
true
-
false
-
an exception is thrown
-
None of these
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).
-
Static-Implemented
-
Implicit
-
Explicit
-
Auto-implemented
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.
-
Shared Methods
-
Instance Methods
-
Both A & B
-
None of the above
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.
-
Hashtable
-
ArrayList
-
Heap
-
Stack
C
Correct answer
Explanation
VB.NET provides collection types like Hashtable, ArrayList, Stack, and Queue. Heap is not a collection type - it's a memory structure used internally by the runtime for allocation, not a class you instantiate for data storage.
-
Implements
-
Uses
-
Imports
-
Overrides
A
Correct answer
Explanation
VB.NET uses the Implements keyword to implement interface members. A class uses Implements InterfaceName to declare it implements an interface, and Implements Interface.Member for each member implementation.
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.
-
A file that contains a section of compiled Java code which, with other class files, can be used to run a Java
-
A file that contains a set of security rules to ensure that Java can't be used to distribute viruses
-
A file that is written by trainees on our courses
-
A file that contains a library of methods and objects
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.
-
creating a subclass
-
creating extra instances of the class
-
allocating more memory to the class
-
making a class more generic
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.
-
public
-
default
-
static
-
final
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.
-
A set of test cases for testing classes of objects
-
An input or output range of values such that only one value in the range becomes a test case
-
An input or output range of values such that each value in the range becomes a test case
-
An input or output range of values such that every tenth value in the range becomes a test case.
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.