Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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
Tim Cooke
Ron McLeod
paul wheaton
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Himai Minh
Bartenders:
Forum:
Programmer Certification (OCPJP)
Doubt in john meyers' question...
Gabriel Ozeas
Ranch Hand
Posts: 30
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi folks, i have a doubt about modifiers in this question from john meyers
import java.util.*; class test implements Comparator<test> { private int x; test(int input) { x = input; } public static void main( String args[] ) { List list = new ArrayList(); list.add(new test(2)); list.add(new test(1)); Collections.sort(list, new test(2)); } public int compare( test t1 , test t2 ) { return t1.x - t2.x; } }
why the compare method can access t1.x and t2.x if they are private? i compile and run this code but no compiler or runtime error appeared...
thxz everyone!
chander shivdasani
Ranch Hand
Posts: 206
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
private members of a class can be accessed by the methods of the same class
Enjoy, Chander
SCJP 5, Oracle Certified PL/SQL Developer
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
collections
Garbage collection output doubt
Please give responses..
One more mock exam question
Comparable or Comparator
More...