954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

abstract method

Hi

I want to make an abstract method. But I always get the error " cannot declare a body because it is marked abstract."
When I delete the return then I get the error than I need a return.

can someone help me please

public  abstract Graphics drawRectangle(Graphics drawarea)
        {
          return drawarea;
        }
superjj
Light Poster
32 posts since Nov 2010
Reputation Points: 10
Solved Threads: 1
 

The very definition of an abstract method in C# is a function declaration without an implementation. Non-abstract derived classes are required to provide the implementation. If you want to provide a default implementation, the method should be virtual rather than abstract.

If you want to keep it abstract just replace the body with a semicolon. That makes it a declaration rather than a definition:

public abstract Graphics drawRectangle(Graphics drawarea);
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Abstract method cannot have any code implementation.
Only overriden from it.

Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: