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

    Default Calling method from another class

    Hi guys,

    i have made two java files as followin:
    1st file:
    public class Reader
    private static BufferedReader stdin =
    new BufferedReader( new InputStreamReader( ) );

    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)

    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?


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


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

    I misread your code, i didnt notice that getString was static:
    Java Code:
    However that wont work, since the line:
    Java Code:
    private static BufferedReader stdin =
    new BufferedReader( new InputStreamReader( ) );
    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, 04:01 PM
  2. Dynamic method calling
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-15-2008, 08:46 AM
  3. method calling?
    By frejon26 in forum New To Java
    Replies: 4
    Last Post: 01-25-2008, 03:38 AM
  4. Help with Calling a method
    By Albert in forum New To Java
    Replies: 3
    Last Post: 07-10-2007, 03: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