Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Abstract method in non-abstract class

Reply
Thread Tools

Abstract method in non-abstract class

 
 
Chris Zopers
Guest
Posts: n/a
 
      08-08-2008
Hello,

I would like to know if it's possible to mark a method as abstract in a
non-abstract class, like this:

public class Test
{
public string NormalMethod()
{
return "somevalue";
}

public abstract string AbstractMethod();
}

When I compile this code I get an error indicating that an abstract
method in a nonabstract class is not possible. But I would like to
inherit from the class and all of it's functionality, only one method
has to be overriden by the inheriting class. Can I do this maybe in an
other way?

Greetings,
Chris

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Rory Becker
Guest
Posts: n/a
 
      08-08-2008
Hello Chris,

> Hello,
>
> I would like to know if it's possible to mark a method as abstract in
> a non-abstract class, like this:
>
> public class Test
> {
> public string NormalMethod()
> {
> return "somevalue";
> }
> public abstract string AbstractMethod();
> }
> When I compile this code I get an error indicating that an abstract
> method in a nonabstract class is not possible. But I would like to
> inherit from the class and all of it's functionality, only one method
> has to be overriden by the inheriting class. Can I do this maybe in an
> other way?


Your class needs to be abstract.

Imagine if it were directly constructable.

What would happen when someone called your abstract emthod?

--
Ror


 
Reply With Quote
 
 
 
 
Göran Andersson
Guest
Posts: n/a
 
      08-08-2008
Chris Zopers wrote:
> Hello,
>
> I would like to know if it's possible to mark a method as abstract in a
> non-abstract class, like this:
>
> public class Test
> {
> public string NormalMethod()
> {
> return "somevalue";
> }
>
> public abstract string AbstractMethod();
> }
>
> When I compile this code I get an error indicating that an abstract
> method in a nonabstract class is not possible. But I would like to
> inherit from the class and all of it's functionality, only one method
> has to be overriden by the inheriting class. Can I do this maybe in an
> other way?
>
> Greetings,
> Chris
>
> *** Sent via Developersdex http://www.developersdex.com ***


That's exactly what the abstract class is for. You can implement some
methods and leave some methods abstract to be implemented by the
inheriting class.

Also consider if virtual methods is useful for you, where you can make a
default implementation in the base class, and override it in the
inheriting class with an implementation specific for that class.

--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using "abstract" on a class with no abstract method Stefan Ram Java 27 08-17-2009 12:36 AM
what is the difference between abstract class and pure abstract class? skishorev@yahoo.co.in C++ 4 05-17-2006 08:07 AM
About abstract class and abstract method Sameer Java 4 08-31-2005 12:59 AM
Deriving abstract class from non-abstract class Matthias Kaeppler Java 1 05-22-2005 01:28 PM
Abstract class with no abstract functions Uzytkownik C++ 3 04-03-2005 05:45 PM



Advertisments