Classes
how to create instances and objects of the base class or the derived class
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Mar 6, 2014, 3:28 AM EST
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.
Ehtesham MehmoodRank #719 · 3.3K reputationPosted Mar 6, 2014, 3:59 AM EST
http://www.dotnetperls.com/class
http://www.csharp-station.com/Tutorial/CSharp/lesson08