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

    Default variable access from another file

    Hi, in c++ we can define a variable as extern but in java i don't know what to do.

    in a file i defined a variable and i want to access this variable from another file in the same package.

    i don't know how

    anybody please

  2. #2
    levent Guest

    Default

    If you want that variable to be read only define it like this:

    Java Code:
    public static final int myGlobalVariable = 10;
    And if you want it to be writable by other classes, then define it like this:

    Java Code:
    public static int myGlobalVariable = 10;
    And if you want it to be visible by just the classes (or files) in the same package, make it protected.

Similar Threads

  1. File Access Through Servlets
    By bipinkrishna15 in forum Java Servlet
    Replies: 1
    Last Post: 05-27-2008, 11:58 AM
  2. how to access shared file/folder in LAN
    By ksheetiz in forum Networking
    Replies: 1
    Last Post: 05-24-2008, 05:54 AM
  3. Need help on a strange file access prob
    By squad in forum Advanced Java
    Replies: 0
    Last Post: 03-21-2008, 11:55 AM
  4. Access a variable
    By Eric in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 09:29 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
  •