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
D
Correct answer
Explanation
A .NET DLL (assembly) can contain unlimited multiple classes - there's no technical restriction. The option D 'Mamy' appears to be a typo for 'Many', but it's clearly the intended correct answer. DLLs are designed to package multiple types together. Options A (One), B (Two), and C (None) are incorrect because DLLs routinely contain many classes in real-world applications.
-
Server-side code
-
Client-side code
-
Both A) and B)
-
None of the above
A
Correct answer
Explanation
Code-behind classes in ASP.NET contain server-side code that executes on the web server. This code handles events, performs business logic, and interacts with databases before the page is rendered to HTML. Client-side code like JavaScript would be in script tags or .js files, not in code-behind classes.
-
Reflection
-
Enumeration
-
Binding
-
Serialization
A
Correct answer
Explanation
Reflection in .NET is the process of inspecting metadata at runtime to discover information about assemblies, modules, and types, and dynamically instantiate or invoke them.
-
Serialization
-
Threading
-
RCW
-
AppDomain
A
Correct answer
Explanation
Serialization is the process of converting the state of an object into a stream of bytes, allowing it to be easily saved to memory, a database, or transmitted over a network.
-
Server-side code
-
Client-side code
-
Both A) and B)
-
None of the above
A
Correct answer
Explanation
In ASP.NET, the code-behind file contains the server-side logic (written in C# or VB.NET) that runs on the web server to process page events, while the client-side code runs in the browser.
A
Correct answer
Explanation
The Base Class Library (BCL) in .NET确实 includes fundamental classes for Collections, I/O, Networking, Security, and other core functionality. This statement accurately describes BCL's purpose and contents.
-
virtual methods
-
Overloaded methods
-
Overridden methods
-
All the Above
D
Correct answer
Explanation
Polymorphism in VB.NET is achieved through method overloading (compile-time polymorphism), virtual methods, and method overriding (runtime polymorphism). Therefore, all of the listed techniques are used to achieve polymorphism.
-
System.Diagnostics.Process
-
System.Object class
-
System.Drawing namespace
-
None of the Above
B
Correct answer
Explanation
In VB.NET, if Option Strict is turned off and a variable is declared without an explicit type (e.g., Dim x), the compiler defaults its type to System.Object, which is the root of the .NET type hierarchy.
-
In VB.NET a child Class can Inherit from 2 Parent Classes
-
Inheritance concept is not supported by .NET
-
Both A) and B)
-
None of the Above
C
Correct answer
Explanation
VB.NET does not support multiple inheritance from classes (only single inheritance with multiple interface implementation). .NET fully supports inheritance as a core object-oriented concept. Both statements A and B are false.
-
Single inheritance using classes
-
Multiple inheritance using interfaces
-
Both A) and B)
-
None of the Above
C
Correct answer
Explanation
VB.NET supports single inheritance for classes (a class can inherit from only one base class) and multiple inheritance for interfaces (a class or interface can implement/inherit multiple interfaces).
-
A method is an implementation of an abstraction
-
A method is an attribute defining the property of a particular abstraction
-
A method is an operation defining the behavior for a particular abstraction
-
A method is a blueprint for making operations
C
Correct answer
Explanation
In object-oriented programming, a method is an operation that defines the behavior for a particular abstraction. It encapsulates the actions or behaviors that objects of a class can perform. Option A is incorrect because methods define behavior, not implementation of abstraction. Option B is incorrect because attributes (not methods) define properties.
-
They pass messages by modifying each other's fields
-
They pass messages by calling each other's instance methods
-
They pass messages by modifying the static variables of each other's classes
-
They pass messages by calling static methods of each other's classes
B
Correct answer
Explanation
In object-oriented programming, objects interact and communicate by invoking (calling) each other's instance methods. Modifying fields directly violates encapsulation, and static methods belong to classes rather than individual object instances.
B
Correct answer
Explanation
Unlike TreeSet, a HashSet does not sort its elements and does not compare them using Comparable. It uses hashCode() and equals(), which are defined on all objects. Therefore, adding a String and an Integer to a HashSet will not cause a ClassCastException.
A
Correct answer
Explanation
A TreeSet relies on natural ordering or a comparator to sort its elements. When adding elements, it compares them using compareTo(). Comparing a String to an Integer throws a ClassCastException at runtime because they are incompatible types.
-
abstract class Link { }
-
native class Link { }
-
final class Link { }
-
abstract final class Link { }
C
Correct answer
Explanation
In Java, the final modifier prevents a class from being subclassed (extended). The abstract modifier requires a class to be extended, making abstract final an illegal combination. native is not a valid modifier for classes.