Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract method

 
Lancy Mendonca
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Had a small query about abstract method:
Why is it not possible to say
abstract class one
{
private abstract void f();
}
The compiler gives an error message
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler gives an error because abstarct methods cannot be declared as private. Here's why -
Abstract classes are incomplete classes. Tagging a method as abstract indicates that the subclass needs to override the method to make the implementation complete. However, we also know private methods cannot be overridden because they are not visible outside the class. This makes abstract and private qualifiers mutually exclusive and hence they cannot be used together.
Hope this helps.
Ajith
 
Lancy Mendonca
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ajith. Your help is appreciated
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic