Click here to Skip to main content
15,893,337 members
Home / Discussions / C#
   

C#

 
GeneralRe: Broken DLL Pin
musefan5-Jun-11 23:28
musefan5-Jun-11 23:28 
AnswerRe: Broken DLL [SOLVED] Pin
musefan5-Jun-11 23:31
musefan5-Jun-11 23:31 
QuestionClasses inheritance and something that confuses me Pin
nstk2-Jun-11 20:54
nstk2-Jun-11 20:54 
AnswerRe: Classes inheritance and something that confuses me PinPopular
Wayne Gaylard2-Jun-11 21:36
professionalWayne Gaylard2-Jun-11 21:36 
AnswerRe: Classes inheritance and something that confuses me Pin
Richard MacCutchan2-Jun-11 21:44
mveRichard MacCutchan2-Jun-11 21:44 
GeneralRe: Classes inheritance and something that confuses me Pin
nstk2-Jun-11 22:02
nstk2-Jun-11 22:02 
GeneralRe: Classes inheritance and something that confuses me Pin
Richard MacCutchan2-Jun-11 22:28
mveRichard MacCutchan2-Jun-11 22:28 
GeneralRe: Classes inheritance and something that confuses me Pin
MicroVirus3-Jun-11 1:40
MicroVirus3-Jun-11 1:40 
nstk wrote:
And this is ok for me, but still I do not understand why is such a declaration useful and what it actually means. If I declare

Employee e = new ContractEmployee()

and e has the properties of the Employee class, why then not write

Employee e = new Employee()

as we "normally" do? What is the difference between those two?


The first code line means you create a new instance of class ContractEmployee. This object in memory *is* a ContractEmployee. You then have a variable e which is an Employee. Since a ContractEmployee is specifically also an Employee (ContractEmployee derives from Employee) this is a valid assigment.
The difference between the two lines is that in the first, e behaves like a ContractEmployee and in the second e behaves like an Employee.
However, through e you can only access members of ContractEmployee which are also part of Employee.

The most important thing to distinguish in these examples is the difference between the actual object created (and in memory), which is specified by new, and the interface you are using to access it.
The actual object you create is different in both examples, but the interface you use to access them is the same.

To properly explain this sample, we'd need to explain almost everything about classes and inheritance, and it seems you're not there yet. So probably, it's best to keep those questions in the back of your head until you get to that subject and ask them again; probably, you'll find you know the answers
GeneralRe: Classes inheritance and something that confuses me Pin
Richard MacCutchan3-Jun-11 3:31
mveRichard MacCutchan3-Jun-11 3:31 
GeneralRe: Classes inheritance and something that confuses me Pin
nstk3-Jun-11 11:48
nstk3-Jun-11 11:48 
GeneralRe: Classes inheritance and something that confuses me Pin
BobJanova3-Jun-11 4:29
BobJanova3-Jun-11 4:29 
GeneralRe: Classes inheritance and something that confuses me Pin
nstk3-Jun-11 20:35
nstk3-Jun-11 20:35 
AnswerRe: Classes inheritance and something that confuses me Pin
Łukasz Nowakowski2-Jun-11 22:05
Łukasz Nowakowski2-Jun-11 22:05 
AnswerRe: Classes inheritance and something that confuses me Pin
_Erik_3-Jun-11 3:35
_Erik_3-Jun-11 3:35 
AnswerRe: Classes inheritance and something that confuses me Pin
Ravi Bhavnani3-Jun-11 5:48
professionalRavi Bhavnani3-Jun-11 5:48 
AnswerRe: Classes inheritance and something that confuses me Pin
Abhinav S3-Jun-11 21:23
Abhinav S3-Jun-11 21:23 
QuestionBasic Question On Constructor Stuff Pin
PozzaVecia2-Jun-11 10:10
PozzaVecia2-Jun-11 10:10 
AnswerRe: Basic Question On Constructor Stuff Pin
Ian Shlasko2-Jun-11 10:15
Ian Shlasko2-Jun-11 10:15 
GeneralRe: Basic Question On Constructor Stuff Pin
PozzaVecia2-Jun-11 10:21
PozzaVecia2-Jun-11 10:21 
AnswerRe: Basic Question On Constructor Stuff Pin
PIEBALDconsult2-Jun-11 16:23
mvePIEBALDconsult2-Jun-11 16:23 
GeneralRe: Basic Question On Constructor Stuff Pin
PozzaVecia3-Jun-11 11:10
PozzaVecia3-Jun-11 11:10 
AnswerRe: Basic Question On Constructor Stuff Pin
BobJanova3-Jun-11 4:34
BobJanova3-Jun-11 4:34 
QuestionGrid rendering problem in windows forms Pin
venomation2-Jun-11 5:38
venomation2-Jun-11 5:38 
GeneralRe: Grid rendering problem in windows forms Pin
thatraja2-Jun-11 8:21
professionalthatraja2-Jun-11 8:21 
AnswerRe: Grid rendering problem in windows forms Pin
Luc Pattyn2-Jun-11 8:47
sitebuilderLuc Pattyn2-Jun-11 8:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.