A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
Joined: Apr 27, 2004
May 23, 2004 02:53:00
private int number = 2;
public static void main(
Test a = new Test(); //why instance can access private member?
but I don't understand that number in Test class is modified privete,why
the instance of Test main method can access number variable?
My Way,My Pace
Joined: Jul 10, 2001
May 23, 2004 06:02:00
That is because main is also inside the class.
all the private variables and methods canbe accessed inside the class any way we want it.
I agree. Here's the link:
subject: private modifier
Regarding access to private members.
private & static
Hierarch of non-static inner class
What is the purpose of instantiating an object in another class?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014