There are a class A. Another class B derived from it.
Now if I do A a = new B(); and B b = new B(); What will
happen in both the statements. And what is the difference
between these two statements.

Answer Posted / nsy

In general, an object reference variable can refer only to
objects of its type.
There is, however, an important exception to C#’s strict
type enforcement. A reference variable of a base class can
be assigned a reference to an object of any class derived
from that base class.
It is important to understand that it is the type of the
reference variable—not the type of the object that it refers
to—that determines what members can be accessed. That is,
when a reference to a derived class object is assigned to a
base class reference variable, you will have access only to
those parts of the object defined by the base class.

Is This Answer Correct ?    6 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Where’s global assembly cache located on the system?

518


What is the use of functional interface?

464


What is variable and its classification?

518


Can an abstract class have a constructor c#?

483


How many types of constructors are available in c#?

521






What is multithreading? What are the problems that comes with multithreading and how to manage them?

539


What is a c sharp?

449


What is a property in c#?

466


What is serialization in dot net?

470


Can we have multiple threads in one app domain?

509


How many variables do you need?

486


How is a loop recorder monitored?

491


What is the data encapsulation?

473


What is an int in c#?

513


Distinguish between a class and struct?

493