adplus-dvertising
frame-decoration

Question

What will be the output of the given code snippet?
class A {}
class B : A {}
class CheckCast 
{
    static void Main() 
    {
        A a = new A();
        B b = new B();
        b = a as B;
        b = null;
        if(b==null)
        Console.WriteLine("The cast in b = (B) a is NOT allowed.");
        else
        Console.WriteLine("The cast in b = (B) a is allowed");
    }
}

a.

Run time error

b.

The cast in b = (B) a is NOT allowed

c.

The cast in b = (B) a is allowed

d.

Compile time error

Answer: (b).The cast in b = (B) a is NOT allowed

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What will be the output of the given code snippet?

Similar Questions

Discover Related MCQs

Q. Which operator among the following supplies the information about characteristics of a typeof?

Q. Which feature enables to obtain information about the use and capabilities of types at runtime?

Q. Choose the namespace which consists of classes that are part of .NET Reflection API:

Q. Choose the correct statement about System.Type namespace:

Q. Choose the class from which the namespace ‘System.Type’ is derived:

Q. What does the following property signify?

MemberTypes MemberType

Q. The property signifies “Obtains a Module object that represents the module (an executable file) in which the reflected type resides”. Choose the property which specifies the following statement:

Q. Choose the method defined by MemberInfo:

Q. What does the following declaration specify?

MethodInfo[] GetMethods()

Q. What does the following code specify?

object Invoke(object obj, object[] parameters)

Q. What does the following method specify?

Type[] GetGenericArguments()

Q. Select the type of multitasking methods that exist:

Q. Choose the correct statement about process-based multitasking:

Q. Choose the statements which indicate the differences between the thread based multitasking and process based multitasking:

Q. What is the advantage of the multithreading program?

Q. Select the two type of threads mentioned in the concept of multithreading:

Q. Number of threads that exists for each of the processes that occurs in the program:

Q. Choose the namespace which supports multithreading programming:

Q. What does the given code snippet specify?

public Thread(ThreadStart start)

Q. Which of these classes is used to make a thread?