?

Log in

Previous Entry | Next Entry

www.questpond.com has created an awesome video for this question which is available at this link http://www.youtube.com/watch?v=jpFij6RD7CA

“Upcasting” means moving subclass object to the parent class object. “DownCasting” is opposite to “Upcasting” moving the parent object to the child object.

                                          c

“Upcasting” is perfectly valid but “Downcasting” is not allowed in .NET. For instance below is a simple “Customer” parent class which is further inherited by a child class “GoldCustomer”.

class Customer
{

}

class GoldCustomer : Customer

{

}


Below is an “upcasting” code where the child parent class gold customer is pushed to the customer class.

Customer obj = new GoldCustomer();

Below is a sample of “downcasting” code where parent class object is tried to move to a child class object, this is not allowed in .NET.

GoldCustomer obj = new Customer(); // not allowed illegal

Copy right www.questpond.com

Buy 600+ Real Time Interview Videos

Call +91-22-66752917 or mail us on questpond@questpond.com for more details on C#, .NET, ASP.NET, SQL Server interview question videos.

SQL Server interview question videos

Latest Month

March 2017
S M T W T F S
   1234
567891011
12131415161718
19202122232425
262728293031 

Tags

Powered by LiveJournal.com