Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ oops
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.
 
Thanks
 
Varun
Posted 9-Apr-13 18:59pm

1 solution

Rate this: bad
good
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.
 
—SA
  Permalink  
Comments
Varun Sareen at 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
Sergey Alexandrovich Kryukov at 10-Apr-13 9:47am
   
This is what you should have done in first place.
Anyway, are you accepting this answer formally (green button)?
—SA
nv3 at 10-Apr-13 2:59am
   
My 5.
Sergey Alexandrovich Kryukov at 10-Apr-13 9:47am
   
Thank you.
—SA

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

  Print Answers RSS
0 OriginalGriff 253
1 Maciej Los 205
2 Nguyen.H.H.Dang 190
3 Peter Leow 185
4 arvind mepani 162


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