?

Log in

No account? Create an account

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

Tags

Latest Month

September 2017
S M T W T F S
     12
3456789
10111213141516
17181920212223
24252627282930
Powered by LiveJournal.com