File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

combination of access & non-access modifiers for a class

 
siva prakash
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am reading K&B book, page :15, and tried following combinations and getting compilation error, Can any one explain me what could be logic for it.

1) private & protected with "final" modifier
2) private & protected with "strictfp" modifier
3) private & protected with "abstract" modifier , i can understand the combination of private & abstract showing compilation error.

Thanks inadvance,
Prakash.
 
Antonio Tercero
Ranch Hand
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends:

final modifier means that you can't change the value of a variable member , and with methods it means that you can't override it so all access modifiers(private , protected, public ..) can be used with final.

abstract modifier means that the method is not implemented.
You can declare an abstract method in an abstract class or an interface.
In an abstract class, you can only apply protected, public or "Default" access modifers: you CAN'T apply private modifier because the first non-abstract method that extends the abstract class doesn't inherits private methods.

Example:


In an interface, all methods declared are by default public and abstract, so you can only use public with abstract.

Finally, a method can't be final and abstract at the same time
final -> can't override the method
abstract -> you must override the method
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic