• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

combination of access & non-access modifiers for a class

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic