Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Trying to understand the "protected" keyword.

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Trying to understand the "protected" keyword.

    When a method has private access it can not be accessed anywhere other than its own class file. With protected I'm confused to when you can not use it because to use any method from another class you have to create a new object anyways, allowing public or protected access.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Trying to understand the "protected" keyword.


  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Trying to understand the "protected" keyword.

    Quote Originally Posted by simpson_121919 View Post
    With protected I'm confused to when you can not use it
    Classes in a different package can not access those protected elements. Multiple packages may be included in one project/executable jar.

    PROJECT
    --packagea
    ---class A
    ----protected int safeFromClassesInB;

    --packageb
    ---class B
    ---class C

    No class in packageb can use the protected int

Similar Threads

  1. [SOLVED] Adding the "final" keyword makes difference, I'm confused with the sequence flow.
    By SmokyBrain in forum Object Oriented Programming
    Replies: 2
    Last Post: April 30th, 2012, 01:50 AM
  2. Is "count" in this loop a keyword?
    By freakinawesome in forum Loops & Control Statements
    Replies: 5
    Last Post: April 25th, 2012, 04:25 AM
  3. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  4. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM