Click here to Skip to main content
11,928,985 members (51,913 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ OOP
Dear Friends,

I was reading an article on whether there could be non abstract methods in abstract classes or not.

Then while reading a question pops up into my mind that is vice-verse can also be true i.e., If some one is willing to make a abstract method in a non abstract class then will it be helpful or it will give a compile time error.?

This question might be novice for some but i am a little low in OOPs concepts theoretically.


Posted 9-Apr-13 19:59pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

No. And you can easily check it up by writing code and trying to compile it. The indication that a class is abstract with the use of the keyword "abstract" is a sort of a fool-proof feature. It's pretty much the like the absence of non-declared variables.

You can define an abstract class with no abstract methods/properties. It is safe and may make sense, as it indicates that the class is intended to be a base class for some non-abstract classes and serve as a common interface. It does not require abstract classes and even late binding.

From the other hand, if there is at least one no abstract method/property, it requires the class to be abstract. If the class was not abstract (allowed instantiation), it would be unsafe, because then the call to the abstract method/property would be a disaster.

The keyword "abstract" applied to the class is less important than the rule explained above, as the "abstractness" could be determined only based on the members. Nevertheless, this is extra convenience and more fool-proof syntax, also more readable.

Varun Sareen 10-Apr-13 1:24am
thanks dear Sergey for such a good explanation to my question.

Though i tried it myself and found the answer.

Thanks once again
This is what you should have done in first place.
Anyway, are you accepting this answer formally (green button)?
nv3 10-Apr-13 2:59am
My 5.
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 10 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100