How is this a method?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kid Programmer
    New Member
    • Mar 2008
    • 176

    How is this a method?

    Hello guys. I have a question. How is:
    Code:
    System.out.println("Hello, world!");
    a method? I haven't typed anything like:
    Code:
    void System.out.println() {
    blahblahblah
    }
    and I never typed:
    Code:
    System.out.println();
    So how is this a method call? Also do you think that Java C++ etc should be called Object Oriented Programming Languages(oop) or Class Oriented Programming Languages(cop). Thanks :-)
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    You haven't written your own System.out.prin tln() method, but one exists. The nice people at Sun made it for you, and so you can call it like any method you've written - by invoking its name and giving it arguments.

    This particular method resides in the class System.out, and I believe out is an inner class of System.

    Comment

    • Kid Programmer
      New Member
      • Mar 2008
      • 176

      #3
      Originally posted by Ganon11
      You haven't written your own System.out.prin tln() method, but one exists. The nice people at Sun made it for you, and so you can call it like any method you've written - by invoking its name and giving it arguments.

      This particular method resides in the class System.out, and I believe out is an inner class of System.
      Oh I see. So it is a built in method that can be called without creating a System.out.prin tln method. Thanks.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by Kid Programmer
        Oh I see. So it is a built in method that can be called without creating a System.out.prin tln method. Thanks.
        No, nothing is 'built in'. The System class is a utility class with all static methods
        and members, that's all. The System class can be written as follows:

        [code=java]
        public final class System {
        private System() { } // no instance possible
        ...
        public static final PrintWriter out= new PrintWriter(); // coupled to stdout;
        }
        [/code]

        If you want to write something to stdout you have to make the 'out' member
        print it; you can reach that object as 'System.out' and to make it print something
        you can do:

        [code=java]
        System.out.prin tln();
        [/code]

        kind regards,

        Jos

        Comment

        • BigDaddyLH
          Recognized Expert Top Contributor
          • Dec 2007
          • 1216

          #5
          Originally posted by Kid Programmer
          So how is this a method call? Also do you think that Java C++ etc should be called Object Oriented Programming Languages(oop) or Class Oriented Programming Languages(cop). Thanks :-)
          You can ask on the C++ what they like to be called -- I believe it's anything but late for dinner.

          The phrase "Object Oriented Programming Language" is too well established to expect it to change.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by BigDaddyLH
            You can ask on the C++ what they like to be called -- I believe it's anything but late for dinner.

            The phrase "Object Oriented Programming Language" is too well established to expect it to change.
            I prefer to call it "I don't want to type in all that bloody code again, better think a
            bit more and have a Grolsch first"-programming.

            kind regards,

            Jos ;-)

            Comment

            • Kid Programmer
              New Member
              • Mar 2008
              • 176

              #7
              Thanks guys. I understand :-)

              Comment

              Working...