A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
access a private member
Lee Xu
Ranch Hand
Joined: Aug 24, 2001
Posts: 77
posted
Jul 20, 2002 10:55:00
0
I know that the object can access the private member of another object of the same class, but forget the example. Can someone give a concrete example on this? Thanks.
Amir Ghahrai
Ranch Hand
Joined: Jun 19, 2002
Posts: 110
posted
Jul 20, 2002 11:27:00
0
Try reading the following link, the private section
http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html
Amir
Dan Chisholm
Ranch Hand
Joined: Jul 02, 2002
Posts: 1865
posted
Jul 20, 2002 13:46:00
0
Here's a simple example.
class A { private String s; private A(String s) {this.s = s;} public static void main (String[] args) { A a1 = new A("A1"); A a2 = new A("A2"); A a3 = new A("A3"); // Access private members of objects a1, a2, a3. System.out.print(a1.s+","+a2.s+","+a3.s); } }
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Lee Xu
Ranch Hand
Joined: Aug 24, 2001
Posts: 77
posted
Jul 20, 2002 16:59:00
0
Thanks for your prompt reply.
Lee
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: access a private member
Similar Threads
How to understand this sentence?
Question on protected
access private member
Not so private
Access to private members
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter