System class is in lang package.
and we know, To access class members we require object of that class.
and we cant create object of System class.
then How do we able to access System.out.println(); inside java program?
So, we don't need an object of System class to access the out field/variable which is static.
Take a look at the "signature" of the out field - public static final PrintStream out
Notice that its public (and static) , which is why you can access it from anywhere.
That won't be the case if it was private, protected or nothing/package.
Sarvya , you also said that - "To access class members we require object of that class"
I'd like to add to that. This is also how you can access member variables of a class -
1 - If they are public and you can get an object of that class.
2 - If the member variable is private, then we need member methods such as getters and setters that let you get and set that member variable.
As an aside, we see the error "The constructor System() is not visible"
for the code below.
Java Newbie with 72% in OCJP/SCJP - Super Confused Jobless Programmer.
I am a "newbie" too. Please verify my answers before you accept them.