Results 1 to 2 of 2
  1. #1
    tariqatherah is offline Member
    Join Date
    Nov 2011
    Posts
    1
    Rep Power
    0

    Question instance private members accessed from other instances of the same type

    public class Test {

    private int someInt;

    public void testMethod(EtQEncryptionUtils testInstance){
    System.out.println(testInstance.someInt);
    }
    }

    how could this class compile, while the testMethod is trying to use testInstance.someInt which is private in testInstance?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default Re: instance private members accessed from other instances of the same type

    The access specifier 'private' works on the class level, i.e. two different objects of the same class can manipulate each others' private members.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. What is the use of marking Instance variable to private
    By rmurali.mcp in forum New To Java
    Replies: 2
    Last Post: 05-31-2011, 10:49 AM
  2. package-private members
    By ilya in forum Advanced Java
    Replies: 6
    Last Post: 05-03-2011, 09:59 AM
  3. private data members?
    By blueduiker in forum New To Java
    Replies: 10
    Last Post: 01-19-2010, 11:13 AM
  4. Replies: 1
    Last Post: 12-09-2009, 12:57 AM
  5. Replies: 1
    Last Post: 06-08-2009, 07:27 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
  •