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.




Answers were Sorted based on User's Feedback



There are a class A. Another class B derived from it. Now if I do A a = new B(); and B b = new B();..

Answer / srushtitha.

here,A is Base class, B is Derived class.
in the first statement "the object of B is stored in parent
clss reference"(Runtime Polymorphism).

-->In the secend statement "the object is creacted for the
child class.

Is This Answer Correct ?    23 Yes 3 No

There are a class A. Another class B derived from it. Now if I do A a = new B(); and B b = new B();..

Answer / ashok kumar

A is a base class, B is a derived class.
Which means we cad access all the data of A class in B class.

Public A
{...}
Public B:A
{...}
Class VoidMain()
{
A a=new B();// Creating object for A class(can access the A
class data only).
B b=new B();// Creating object for B class(can access the
A,B class data).
}

Is This Answer Correct ?    12 Yes 3 No

There are a class A. Another class B derived from it. Now if I do A a = new B(); and B b = new B();..

Answer / 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



More C Sharp Interview Questions

WHAT IS THE DIFFERENCE BETWEEN STRING AND STRING BUILDER ?

3 Answers  


what is Anonymous Method.? and What is shadowing?

2 Answers   Infosys, ATS,


What namespaces are necessary to create a localized application?

2 Answers   Visual Soft,


i have a table named login in mysql database containing (empid,fname,lname,mobno,emailid,usrname,usrpwd) i have 2 textboxes in which i enter my username and pwd..so based on what is entered in those textboxes it should retreive all other details of dat username in the remaining 6 textboxes..i want the code for this...

1 Answers   Royal Enfield,


Can you prevent your class from being inherited and becoming a base class for some other classes?

2 Answers   Mind Tree,






Why can?t you specify the accessibility modifier for methods inside the interface?

3 Answers   Mind Tree,


What is a delegate?

5 Answers  


What happens in synchronisation?

2 Answers   Tech Mahindra,


can u tell me any one steps for creatting sn.k

2 Answers  


what is the difference between finally and dispose methods?

3 Answers   Patni, HCL,


windows c# using datagridview in edit form sql server

0 Answers  


why delegate is type safe?

0 Answers   IBS,






Categories