Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23
  1. #21
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    package private? So all classes in the same package can access this class (class w/out any modifiers), and at the same time they can't because it's private. That makes no sense to me lol.

    EDIT: "A class may be declared with the modifier public, in which case that class is visible to all classes everywhere. If a class has no modifier (the default, also known as package-private), it is visible only within its own package (packages are named groups of related classes—you will learn about them in a later lesson.)," http://download-llnw.oracle.com/java...sscontrol.html

    So I tested it out:

    Java Code:
    package hi;
    
    public class SomeStuff {
    
    }
    
    class NotSomestuff { //okay
    	
    }
    Java Code:
    package hi;
    
    public class NotNotSomeStuff {
    	public static void main(String[] args) {
    		SomeStuff test = new SomeStuff(); //okay
    		NotSomestuff test1 = new NotSomestuff(); //okay
    	}
    }
    Java Code:
    import hi.*;
    
    public class SomeBanalName {
    	public static void main(String[] args) {
    		SomeStuff test = new SomeStuff(); //okay
    		NotSomestuff test1 = new NotSomestuff(); //error!
    	}
    }
    So basically, it is the same thing as protected but it's not at the same time because one file can have many package-private modifiers.
    Last edited by Lil_Aziz1; 07-29-2010 at 05:14 AM.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  2. #22
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Damn! I wrote "package private" and then thought "that doesn't look right".
    :)

  3. #23
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    :confused: Looks like Lil_Aziz is contradicting himself with his edit :)
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. class Declaration
    By mahtab in forum New To Java
    Replies: 1
    Last Post: 11-01-2009, 07:49 AM
  2. Replies: 14
    Last Post: 05-28-2009, 06:44 AM
  3. global declaration in java
    By gpveena20 in forum New To Java
    Replies: 13
    Last Post: 02-12-2009, 11:25 PM
  4. whats wrong with this class declaration?
    By blossompark in forum New To Java
    Replies: 5
    Last Post: 11-30-2008, 03:18 AM
  5. Declaration
    By asifahmed in forum New To Java
    Replies: 1
    Last Post: 04-05-2008, 06:38 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
  •