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 Private and Protected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Private and Protected" Watch "Private and Protected" New topic
Author

Private and Protected

Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
Hello
What the main difference between private and protected? What is the meaning of private protected int seconds = 23;? If I have private integer seconds = 23; in private class Hello, Can I change the value of integer seconds when I am in the private class Hello?
Thanks
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
Originally posted by Mike Shn:
Hello
What the main difference between private and protected? What is the meaning of private protected int seconds = 23;? If I have private integer seconds = 23; in private class Hello, Can I change the value of integer seconds when I am in the private class Hello?
Thanks

You should get an error , because using private and protected is not allowed in combination. What i found interesting that JBuilder allowed you to compile but though a warning saying that they took out private and left just protected.
Yes you can change the value of youru seconds variable in that class. What you can't do is access that variable outside it. you can define a public geter that will change that value for you. This is called encapsulation.

Val SCJP <BR>going for SCJD
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5018
    
    8

Originally posted by Val Dra:
you can define a public geter that will change that value for you. This is called encapsulation.

Well, not really. Check out this article: "Encapsulation is not Information Hiding"
Junilu

Junilu - [How to Ask Questions] [How to Answer Questions]
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
i read that article last week .
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

I sense a holy war.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5018
    
    8

Originally posted by Mike Curwen:
I sense a holy war.

I like to think of it as more of a crusade, really. I may have to work with some of these folks
I find it frustrating sometimes to see how much attention is given to the mechanics of the language and yet little given to the principles of Object Orientation. If you look at some of the code in the Java Tutorial, you can't help wonder sometimes if the people who wrote the sample programs knew anything about object orientation or not.
It's even more amazing (and frightening) when I show people the initial UML diagrams and code in the first chapter of "Refactoring" and ask them if it is object-oriented and they reply "Yes."
It seems that even though Java is supposed to be more OO, it still takes more effort to write OO code than it does to write non-OO code.
Junilu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Private and Protected