September 1st, 2013, 05:06 AM
Question about built-in classes (Math and System)
In the book i'm reading, it says that "Even if you didn't know it, you've already been using classes from a package. System (System.out.println()), String and Math (Math.random()), all belong to the java.lang. package."
My question is: if Math and System are classes, how come I didn't have to instantiate them, in order to use their methods? (Math.random(), System.out.println())
September 1st, 2013, 08:24 AM
You should read the API doc for those methods and classes.
The methods in the Math class are static which means they do not require instances of the class.
out is a static variable in the System class. It contains a reference to an instance of the PrintStream class.
Last edited by NormR; September 1st, 2013 at 08:26 AM.
September 1st, 2013, 08:28 AM
forgot all about the static property.