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
What is class sortedlist underneath?
What is the difference between finalize() and dispose() methods?
Can you explicitly call a destructor?
What is use of abstract class in c#?
What is the main method in c#?
What is the use of table aliases?
What is a partial class in c#?
Can you mark static constructor with access modifiers?
Is java better than c sharp?
How much time will it take to learn unity?
What is int32 maxvalue?
Describe ways of cleaning up objects in c#.
How would you describe encapsulation in c#?
what are pointer types in c#
Explain the various types of classes used in c#?