File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Abstract classes and methods and access specifiers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract classes and methods and access specifiers" Watch "Abstract classes and methods and access specifiers" New topic
Author

Abstract classes and methods and access specifiers

Sid Kar
Greenhorn

Joined: May 23, 2011
Posts: 10
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

I'll say you should try your "can" questions and then ask us in detail "why" questions.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Sid Kar
Greenhorn

Joined: May 23, 2011
Posts: 10
OK, I will try it in a compiler and get back to you.
Sid Kar
Greenhorn

Joined: May 23, 2011
Posts: 10
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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Oct 13, 2005
Posts: 38363
    
  23
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

Joined: May 23, 2011
Posts: 10
OK, thanks guys.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Abstract classes and methods and access specifiers