Results 1 to 2 of 2

Thread: Some Problem

  1. #1
    Tony Stark is offline Member
    Join Date
    Aug 2016
    Rep Power

    Default Some Problem

    i wrote this :

    public void var1()
    FileOutputStream File = new FileOutputStream("something") ;
    public void var2()
    PrintWriter FileInput = new PrintWriter(File);

    ok , in the second method it won't recognize "File" because it was defined in another method .
    my question is can i define "File" in the first method then call it somehow in the second method using some code ?

    thanks ,
    Tony .

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: Some Problem

    There are several ways. One is to make the variable an instance field which would be available to all instance methods. The other way would be to
    pass the variable to the method.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 5
    Last Post: 11-11-2015, 12:16 PM
  2. Replies: 0
    Last Post: 11-07-2012, 12:44 PM
  3. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 03:43 AM
  4. Replies: 9
    Last Post: 09-21-2010, 04:15 PM
  5. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 06:12 AM

Posting Permissions

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