classes
how to create instances and objects of the base class or the derived class
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ehtesham MehmoodPosted Mar 6, 2014, 8:59 AM
http://www.dotnetperls.com/class
http://www.csharp-station.com/Tutorial/CSharp/lesson08
VulpesPosted Mar 6, 2014, 8:28 AM
using System;
class Base
{
}
class Derived : Base
{
}
class Program
{
static void Main()
{
Base b = new Base();
Derived d = new Derived();
Base c = new Derived();
Derived e = new Base(); // compiler error
Derived f = (Derived)c; // OK as c refers to a Derived object
}
}
Note that instances or objects of a class are different names for the same thing.
Note also that you can assign a reference to a Derived object to a variable of type Base but not the other way around.