• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract classes and methods and access specifiers

 
Sid Kar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I'd like to know if

1. Abstract classes can have an access specifier or not? Why or why not?

2. Abstract methods can have an access specifier or not? Why or why not?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll say you should try your "can" questions and then ask us in detail "why" questions.
 
Sid Kar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I will try it in a compiler and get back to you.
 
Sid Kar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I tried and found out the following:

1. Abstract classes can be made public or package, but not private or protected.

2. Abstract methods can be made public or package or protected, but not private.

Please can somebody tell me why?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sid Kar wrote:
1. Abstract classes can be made public or package, but not private or protected.

http://www.coderanch.com/t/410134/java/java/private-protected-class
Sid Kar wrote:
2. Abstract methods can be made public or package or protected, but not private.

private method is implicitly final. so it wont make any sense to mark it as abstract, since concrete subclasses have to override abstract method.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write down what an abstract method is for, and it should become obvious why it cannot have a private modifier (not “specifier”).
Work out what private and protected mean and try to work out what they would mean for top‑level classes. then you can see why the only access modifier permissible for a top‑level class is public.
 
Sid Kar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, thanks guys.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic