• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

illegal combination of modifiers: private and protected

 
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I am trying to run this code and getting error illegal combination of modifiers: private and protected. Please tell me am i doing something wrong. I have read that we can use combination ot private protected access modifiers in Java HandBook then why it is showing illegal ?
 
Sheriff
Posts: 16959
286
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Please quote the exact passage from the book. Maybe you misunderstood it or it's poorly worded.

Scope modifiers like public, protected, and private are mutually exclusive, you can have only one of them on a declaration. Other modifiers like static and final may be combined with the scope modifier.
 
Rahulkk Kumar
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If you want to restrict an element such that it is only visible to subclasses, regardless of what package they are in, then declare them private protected.




There is an example in book and they declare variable with combination of two modifiers e.g.

private protected int n_pripro = 4;

If you could search on google book, book name - Java HandBook Page no. 136 If forum allow me i would paste the link of book.
 
Junilu Lacar
Sheriff
Posts: 16959
286
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a typographical error. They meant private or protected.
 
Junilu Lacar
Sheriff
Posts: 16959
286
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As for the example, well, that's just poor editing and technical review.
 
Junilu Lacar
Sheriff
Posts: 16959
286
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are better learning materials available out there. The Official Java Tutorials is a good place to start. Another free resource cited in these forums recently is this http://mooc.fi/courses/2013/programming-part-1/ which, after looking over it myself, looks pretty comprehensive in terms of materials and exercises you can complete for practice. I would stay away from that book you're using now, given the wrong information it contains.
 
Rahulkk Kumar
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If They meant 'private or protected' then the whole statement must be wrong because private member is not visible to subclass.
private member can be only use within same class where it is declared.  
 
Junilu Lacar
Sheriff
Posts: 16959
286
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rahulkk Kumar wrote:If They meant 'private or protected' then the whole statement must be wrong because private member is not visible to subclass.
private member can be only use within same class where it is declared.  



I missed that part about visibility in subclasses. You're right, it should only be protected then.
 
Rahulkk Kumar
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the answer and study resources
 
Marshal
Posts: 75708
354
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rahulkk Kumar wrote:. . . private protected int n_pripro = 4; . . .

Good grief! That isn't a misprint at all. For one thing the format of that variable is not normal for Java®; it looks like an escape from C. In fact many older Java® applications look like C applications with a slightly different syntax.
The private protected access was only permitted in some early versions of JDK1.0. It has been removed and the combination will no longer compile. I have never seen private protected before. That book must be so old it belongs in a museum. But it is useless for learning Java® programming.

And welcome to the Ranch
 
Rahulkk Kumar
Greenhorn
Posts: 9
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it Thanks for the info.
If someone searching the same and want to know what was private protected?
The meaning of private protected was to limit visibility strictly to subclasses and remove package access.
Private Protected the combination of these modifier no longer support in Java Programming due to inconsistency.
I hope it would help other
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:The private protected access was only permitted in some early versions of JDK1.0. It has been removed...


And If it means what I think it does, then I say it's a pity.

But then again, I've always disagreed with Java's interpretation of protected - not to mention "default" - access.

Winston
 
Campbell Ritchie
Marshal
Posts: 75708
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I agree with you that private protected was useful.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was curious about why private protected would cause inconsistencies. I didn't find an answer to that question, but found a bit of information here:


Early on, the Java language allowed for certain combinations of modifiers, one of which was private protected. The meaning of private protected was to limit visibility strictly to subclasses (and remove package access). This was later deemed somewhat inconsistent and overly complex and is no longer supported.[5]

[5] The meaning of the protected modifier changed in the Beta2 release of Java, and the private protected combination appeared at the same time. They patched some potential security holes, but confused many people.


Apparently, initially protected had the same meaning in Java as in C++ (i.e. subclasses only, not classes in the same package) but for some reason they changed that before Java 1.0 came out, and then also added private protected which was supposed to mean what protected means in C++. And then they removed that again because it was too confusing.
 
It's never done THAT before. Explain it to me tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic