473,383 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Abstract method in non-abstract class

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 ***
Aug 8 '08 #1
2 1229
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?

--
Rory
Aug 8 '08 #2
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
Aug 8 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Adrian Parker | last post by:
For some reason when I call validateFields before .Update (see below), I get this error: "Consumer's even handler called a non-reentrant method in the provider" However if I comment out the...
31
by: Chris S. | last post by:
Is there a purpose for using trailing and leading double underscores for built-in method names? My impression was that underscores are supposed to imply some sort of pseudo-privatization, but would...
20
by: Tim Martin | last post by:
Hi, I came across a detail in "C++ Gotchas" by Stephen Dewhurst that confused me a bit. The author states: 'C++ has no "methods." Java and Smalltalk have methods. When you talk about an...
7
by: Code4u | last post by:
In the sample code below I don't understand why the indicated line of code fails to compile. I naively thought that the compiler would use the std::string overload because it would match the...
2
by: Olaf | last post by:
I have a frameset page witch contains the myFuc() function. The function is accessed from a page in one of the frames in the frameset. An example is shown below. <input...
1
by: Xiangliang Meng | last post by:
Hi, all. Recently, I find there is a way in our project to maintain a global set in many files by using preprocessing directives. I'm wondering if we could find a better method for this. Many...
1
by: tparks69 | last post by:
I get the error: ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Insert' that has parameters: last_name, first_name, email, role_id, user_id, modified_by, modified_date...
3
by: csharpula csharp | last post by:
Non-static method requires a target appeares when I am trying to activte nunit (test). Any clue? Thank you! *** Sent via Developersdex http://www.developersdex.com ***
5
by: titan nyquist | last post by:
I have launched threads with void methods, like so: TestClass testClass = new TestClass(); Thread testThread = new Thread(testClass.Launch); testThread.Start(); Where testClass.Launch is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.