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

FOR EXAMPLE : CLASS Dotnet { } creating object: Dotnet dn=new Dotnet(); NOW THE QUESTION IS WHICH IS CALLED AS OBJECT ? EITHER dn OR new Dotnet() and CAN YOU PROVE YOUR ANSWER????? PLEASE REPLY...

2 Answers  


Write one code example for compile time binding and one for run time binding? What is early/late binding?

0 Answers  


What is difference between C# and VB.NET?

0 Answers   CDC,


what is the scope of anonymous type ?

0 Answers   Wipro,


Trace the O/p for a program on inheritance and Polymorphism. 3 classes A,B,C A with two methods public virtual SomeMethodA public virtual SomemoreMethodA B:A overide virtual SomeMethodA C:B new Method SomeMethodA override SomeMoreMethodA main method { b new instance of B b.SomeMethodA b.SomeMoreMethodA b1 new instance of C b1.SomeMethodA b1.SomeMoreMethodA }

1 Answers  






What is the difference between CONST and READONLY?

0 Answers   BirlaSoft,


How will U encapsulate button trigger event into text_box event of Pressing Enter key?

3 Answers   TCS,


What is platform independence"?

0 Answers   DELL,


Explain about throw keyword?

10 Answers   Emphasis, Satyam, HCL,


how many catch we can write in thye program?

2 Answers  


How to use the sreamReader class to read form a text file?

0 Answers   MCN Solutions,


What are the access allowed for compilation units(namespace),class and structs and what are its default access?

1 Answers   TCS,






Categories