Implementing abstract classes

P

puzzlecracker

0) What is the convention name for derived classes?
1) If we implement methods in abstract class, do we still need to
declare them as abstract?
2) Are we allowed to override methods in derived classes that are
already implemented in abstract?
3) Are there a different accessibility levels when I inherit class,
like (public, protected, private), like class A:public B?


Thanks
 
J

Jon Skeet [C# MVP]

puzzlecracker said:
0) What is the convention name for derived classes?

There isn't one really. Abstract base classes sometimes have a "Base"
suffix.
1) If we implement methods in abstract class, do we still need to
declare them as abstract?
No.

2) Are we allowed to override methods in derived classes that are
already implemented in abstract?

Yes, so long as they're still virtual (i.e. not marked with "virtual").
3) Are there a different accessibility levels when I inherit class,
like (public, protected, private), like class A:public B?

You can't specify an access modifier there.
 
P

puzzlecracker

Yes, so long as they're still virtual (i.e. not marked with "virtual").


I don't understand this one? should virtual be specified next to the
abstract method in base class?
 
J

Jon Skeet [C# MVP]

puzzlecracker said:
I don't understand this one? should virtual be specified next to the
abstract method in base class?

No, if it's an abstract method it's necessarily virtual - but if you've
implemented the method in the abstract class, that method isn't virtual
by default.
 
I

Ignacio Machin ( .NET/ C# MVP )

0) What is the convention name for derived classes?

As you need.
1) If we implement methods in abstract class, do we still need to
declare them as abstract?
nop, you will get a compiler error
2) Are we allowed to override methods in derived classes that are
already implemented in abstract?
as long as they are virtual, of course
3) Are there a different accessibility levels when I inherit class,
like (public, protected, private), like class A:public B?
no
 
M

Mike Schilling

Jon said:
No, if it's an abstract method it's necessarily virtual - but if
you've implemented the method in the abstract class, that method
isn't virtual by default.

Agreed, but I still don't understand the "not".
 
J

Jon Skeet [C# MVP]

Subject: Re: Implementing abstract classes
From: Jon Skeet [C# MVP] <[email protected]>

Mike Schilling said:
Agreed, but I still don't understand the "not".

Oh, sorry, I see what you mean. My fault entirely. I meant "not marked
with sealed" for methods which are already overriding a previous
implementation, and "marked with virtual" for other methods.

Apologies - I've got about 20 different things going on here and a
useless internet connection :(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top