Results 1 to 3 of 3
  1. #1
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Question Question about Variable Scope

    When you define a variable like so:

    Java Code:
    String example;
    Without putting any scope before String, does that make it public by default?

    Thanks,
    ~Solarsonic

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    That's not a scope thing, scope deals with how long the object stays around. However to answer your question, the default is package access which gives access to anything inside the same package.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default

    It also depends on where that variable declaration appears. At the class level, it creates an instance field with default, or package-private access.

    Inside a constructor or method, it creates a local variable (the only type of variable that can be created in that scope).

    db

Similar Threads

  1. Elementary question on variable references
    By Shayke_ in forum New To Java
    Replies: 1
    Last Post: 02-09-2011, 05:35 PM
  2. A little confused (class variable scope?)
    By Vase in forum New To Java
    Replies: 11
    Last Post: 02-03-2011, 03:51 AM
  3. variable scope between classes
    By newbie123 in forum New To Java
    Replies: 6
    Last Post: 03-04-2010, 12:20 AM
  4. Variable Scope
    By Laura Warren in forum New To Java
    Replies: 3
    Last Post: 01-11-2009, 11:16 PM
  5. Replies: 1
    Last Post: 10-02-2008, 04:06 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
  •