#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    132
    Rep Power
    2

    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())
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    You should read the API doc for those methods and classes.
    http://docs.oracle.com/javase/7/docs/api/

    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 07:26 AM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    132
    Rep Power
    2
    thanks MormR.

    forgot all about the static property.

IMN logo majestic logo threadwatch logo seochat tools logo