Is there any way to instantiate the System class?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Siddarth777
    New Member
    • Sep 2010
    • 28

    Is there any way to instantiate the System class?

    hi, am a newbie java programmer

    as we know that when we want to print anything on console
    System.out.prin tln is used

    but i want to instantiate the system class such that i can write the code as


    System.obj1.pri ntln("hello world")

    is there any way to do that

    i wrote a sample code but it is not working
    Code:
    class helloworld
    {
       System obj1=new System();
       System.obj1.println("hello world");
    }
    but i am getting an error


    The constructor System() is not visible
    obj1 cannot be resolved or is not a field

    please help, if there is any way to do that please tell me

    thanks in advance
    siddarth
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    You need to read-up on C++ classes. If you do not use an access specifier (public:,privat e: or protected:) data and methods are private by default and cannot be accessed directly.
    BTW a class ends with a ';' e.g,:'};'

    Comment

    • johny10151981
      Top Contributor
      • Jan 2010
      • 1059

      #3
      Besides you have defined like this
      System obj1=new System();

      now you have a object name obj1
      Now if you want to access method(that is available) you will have to do like below:
      obje.println("H ello world");

      if println is a static function then you do not need to define the object. all you need to do is

      System.println( "Hello world");

      Comment

      • Siddarth777
        New Member
        • Sep 2010
        • 28

        #4
        johny10151981

        thanks a lot for your reply but no luck
        when i do as you say
        a new error message pops up, saying
        UNRESOLVED COMPILER ERROR

        i am unable to understand where i went wrong

        Comment

        Working...