Call method from another class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asahli
    New Member
    • Dec 2007
    • 1

    Call method from another class

    Hi guys,
    i have made two java files as followin:
    1st file:
    import java.io.*;
    public class Reader
    {
    private static BufferedReader stdin =
    new BufferedReader( new InputStreamRead er( System.in ) );

    public static void main ( String [] args ) throws IOException
    {
    System.out.prin tln( "input = " + getString());

    }


    public static String getString() throws IOException
    {
    String input = stdin.readLine( );
    return input;
    }

    }



    and the 2nd file is:
    public class Test01
    {
    public static void main(String[] arguments)
    {
    System.out.prin tln(Reader.getS tring());
    }
    }



    The problem is that i could'nt call the getString method from Test01 class????
    could any one take a look and tell me about it?


    thanks
  • neha lalit
    New Member
    • Dec 2007
    • 1

    #2
    Originally posted by asahli
    Hi guys,
    i have made two java files as followin:
    1st file:
    import java.io.*;
    public class Reader
    {
    private static BufferedReader stdin =
    new BufferedReader( new InputStreamRead er( System.in ) );

    public static void main ( String [] args ) throws IOException
    {
    System.out.prin tln( "input = " + getString());

    }


    public static String getString() throws IOException
    {
    String input = stdin.readLine( );
    return input;
    }

    }



    and the 2nd file is:
    public class Test01
    {
    public static void main(String[] arguments)
    {
    System.out.prin tln(Reader.getS tring());
    }
    }



    The problem is that i could'nt call the getString method from Test01 class????
    could any one take a look and tell me about it?


    thanks
    import java.io.*;
    public class Test01
    {
    public static void main(String[] args) throws IOException
    {
    System.out.prin tln(Reader.getS tring());
    }
    }
    now try ,It will work.

    Comment

    • karthickkuchanur
      New Member
      • Dec 2007
      • 156

      #3
      Originally posted by neha lalit
      import java.io.*;
      public class Test01
      {
      public static void main(String[] args) throws IOException
      {
      System.out.prin tln(Reader.getS tring());
      }
      }
      now try ,It will work.

      hai
      u have to inherit the parent class

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by asahli
        The problem is that i could'nt call the getString method from Test01 class????
        could any one take a look and tell me about it?
        It's a compilation problem right? The compiler complains that it can't find a Reader
        class. Next time when you're stuck show us exactly what your compiler showed you.
        Fire up javac like this for starters:
        Code:
        javac -help
        You'll see that you can set a classpath where your already compiled classes are
        stored. Javac needs that path to be able to read your compiled Reader class and
        check whether or not you've been cheating or goofing etc.

        It has nothing to do with parent classes or what else; your compiler wants to know
        where that Reader class is; no more no less.

        kind regards,

        Jos

        Comment

        Working...