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
Is c# code is unmanaged or managed code?
What is delegates in c# and uses of delegates?
Is arraylist generic in c#?
How can we set the class to be inherited, but prevent the method from being over-ridden?
What is difference between dictionary and hashtable?
What is singleordefault?
What is a console in c#?
Does the variables of a private class-level inherited?
What is sql transaction in c#?
What is a class in unity?
Why are c# strings immutable?
3. Use layered architecture for coding. s.no name description 1 abc xxxxxxxxx 2 abc xxxxxxxxx 3 4 5 6 7 8 Select all Clear all Add Delete Name Description Save close
Which namespaces are necessary to create a localized application?
What is the use of 0 in c#?
What is use of console?