Explore these 30 multiple-choice questions on advanced object-oriented programming concepts in VB.NET, covering topics such as interfaces, abstract classes, delegates, events, reflection, and late binding. Perfect for boosting your VB.NET knowledge!
Advanced Object-Oriented Programming:
Interfaces and Abstract Classes
Which of the following is true about an interface in VB.NET? a) An interface can contain method implementations. b) An interface can inherit from other interfaces. c) An interface cannot be implemented by a class. d) An interface can only contain properties.
In VB.NET, an abstract class can have: a) Only abstract methods. b) Only concrete methods. c) Both abstract and concrete methods. d) No methods at all.
Which of the following is the correct way to declare an interface in VB.NET? a) Interface IExample b) Interface Example() c) Class IExample d) Abstract Class IExample
Which statement is true about abstract methods in VB.NET? a) They can be defined in both abstract and non-abstract classes. b) They must be implemented in the same class. c) They don’t need to be implemented by derived classes. d) They can be declared in interfaces only.
Can a VB.NET class implement multiple interfaces? a) Yes, but it must implement all methods in the interfaces. b) No, a class can only implement one interface. c) Yes, but it must inherit from at least one abstract class. d) No, interfaces cannot be implemented.
Delegates and Events
A delegate in VB.NET is best described as: a) A type that holds a reference to a method. b) A method that performs actions asynchronously. c) A class that handles events. d) A variable that stores data for events.
Which of the following is used to declare a delegate in VB.NET? a) Delegate Sub MyDelegate() b) Sub MyDelegate() Delegate c) Public Delegate MyDelegate d) MyDelegate As Delegate Sub
In VB.NET, events are typically associated with: a) Delegates b) Methods c) Properties d) Variables
How do you raise an event in VB.NET? a) Using the RaiseEvent keyword b) Calling the event like a method c) Using the EventHandler class d) Using RaiseEvent only inside the delegate
Which of the following correctly defines an event in VB.NET? a) Public Event OnClick() As EventHandler b) Public Delegate EventHandler OnClick() c) Event OnClick As Public EventHandler d) Delegate OnClick Public EventHandler
Reflection and Late Binding
Which of the following methods is used for late binding in VB.NET? a) Activate b) InvokeMember c) CreateInstance d) LateBind
What is the purpose of the Type.GetType() method in reflection? a) To dynamically call a method at runtime. b) To get the type of a class at runtime. c) To load an assembly into memory. d) To bind a method to a delegate at runtime.
Reflection in VB.NET allows you to: a) Compile code at runtime. b) Dynamically examine and modify the metadata of types. c) Execute methods without a delegate. d) Encrypt and decrypt data at runtime.
Which class in VB.NET is primarily used for late binding? a) Reflection b) Object c) Activator d) DynamicObject
How can you obtain the methods of a class using reflection? a) Using the GetMethods() function b) Using the Invoke() method c) Using the GetProperties() function d) Using the GetFields() function
Which of the following is an example of using reflection for late binding? a) Calling a method using the InvokeMember method b) Defining a method in a class c) Binding an event with a delegate d) Compiling code dynamically
In VB.NET, reflection can be used to: a) Generate code at runtime. b) Convert one class into another. c) Change the visibility of members of a class. d) Dynamically invoke methods of a class at runtime.
What type of object is returned by the Type.GetType() method? a) A MethodInfo object b) A Type object c) A Class object d) A Delegate object
Late binding allows you to: a) Bind methods at compile time. b) Call methods based on string names at runtime. c) Call methods from a static class. d) Call private methods at runtime.
Which of the following is an example of using delegates with events in VB.NET? a) Public Event MyEvent As EventHandler b) Public Delegate Sub MyEvent() c) Dim MyDelegate As New EventHandler(MyEvent) d) Dim MyEvent As New Delegate MyEvent()
Which class provides reflection capabilities in VB.NET? a) Type b) Activator c) Reflection d) EventHandler
What is the purpose of the MethodInfo class in reflection? a) To get information about an assembly. b) To define custom methods dynamically. c) To access method metadata of types. d) To invoke methods on objects.
In VB.NET, how is an event handler associated with an event? a) By using the Handles keyword. b) By using the AddHandler keyword. c) By defining a delegate. d) By using reflection.
Which of the following is an example of invoking a method using late binding? a) InvokeMember("MethodName", BindingFlags.InvokeMethod, Nothing, obj, Nothing) b) obj.MethodName() c) Activate("MethodName") d) obj.Invoke("MethodName")
Reflection can be used to: a) Invoke methods dynamically at runtime. b) Determine the class type at compile time. c) Modify the compiler behavior. d) Optimize code execution.
What does the BindingFlags enumeration define in VB.NET? a) How reflection interacts with an object. b) The method signature of an object. c) The visibility of object properties. d) The location of methods in an assembly.
How do you define an event with a custom delegate in VB.NET? a) Public Event EventName As MyDelegate b) Event EventName As Public MyDelegate c) Delegate EventName As MyDelegate d) Custom Event EventName
Which method is used to create a new instance of a class using reflection? a) CreateObject b) Activator.CreateInstance c) Type.InvokeMethod d) DynamicObject.CreateInstance
How do you declare an abstract class in VB.NET? a) Class AbstractClass b) Abstract Class ClassName c) Class ClassName Inherits Abstract d) Public Abstract Class ClassName
Which of the following is a feature of reflection in VB.NET? a) It enables dynamic invocation of methods based on method signatures. b) It compiles code at runtime. c) It automatically handles event delegation. d) It allows direct memory access.
Answers
Qno
Answer
1
b) An interface can inherit from other interfaces.
2
c) Both abstract and concrete methods.
3
a) Interface IExample
4
a) They can be defined in both abstract and non-abstract classes.
5
a) Yes, but it must implement all methods in the interfaces.
6
a) A type that holds a reference to a method.
7
a) Delegate Sub MyDelegate()
8
a) Delegates
9
a) Using the RaiseEvent keyword
10
a) Public Event OnClick() As EventHandler
11
b) InvokeMember
12
b) To get the type of a class at runtime.
13
b) Dynamically examine and modify the metadata of types.
14
b) Object
15
a) Using the GetMethods() function
16
a) Calling a method using the InvokeMember method
17
d) Dynamically invoke methods of a class at runtime.
18
b) A Type object
19
b) Call methods based on string names at runtime.
20
a) Public Event MyEvent As EventHandler
21
c) Reflection
22
c) To access method metadata of types.
23
b) By using the AddHandler keyword.
24
a) InvokeMember("MethodName", BindingFlags.InvokeMethod, Nothing, obj, Nothing)
25
a) Invoke methods dynamically at runtime.
26
a) How reflection interacts with an object.
27
a) Public Event EventName As MyDelegate
28
b) Activator.CreateInstance
29
b) Abstract Class ClassName
30
a) It enables dynamic invocation of methods based on method signatures.