Results 1 to 2 of 2
  1. #1
    asahli is offline Member
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Default Calling 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 InputStreamReader( System.in ) );

    public static void main ( String [] args ) throws IOException
    {
    System.out.println( "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.println(Reader.getString());
    }
    }



    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

  2. #2
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    Java Code:
    Reader r = new Reader();
    r.getString();
    Thats in your test01 file of course. Thats called creating an instance of a class.

    edit:
    I misread your code, i didnt notice that getString was static:
    Java Code:
    Reader.getString();
    However that wont work, since the line:
    Java Code:
    private static BufferedReader stdin =
    new BufferedReader( new InputStreamReader( System.in ) );
    will never be executed, stdin is going to be null.

Similar Threads

  1. Calling a method in another class
    By uncopywritable in forum New To Java
    Replies: 9
    Last Post: 10-22-2012, 05:01 PM
  2. Dynamic method calling
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-15-2008, 09:46 AM
  3. method calling?
    By frejon26 in forum New To Java
    Replies: 4
    Last Post: 01-25-2008, 04:38 AM
  4. Help with Calling a method
    By Albert in forum New To Java
    Replies: 3
    Last Post: 07-10-2007, 04:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •