Results 1 to 3 of 3
  1. #1
    Felissa is offline Member
    Join Date
    Jun 2007
    Posts
    95
    Rep Power
    0

    Default Question of private member

    I am trying to access the private member of a class from outside is it possible.
    My friend told to me it's possible.
    Do you know how can I resolve this?

    Felissa:p

  2. #2
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default RE: Question of private member

    It is diificult but possible. Basically you will need to use reflection and force the field to be visible.
    Java Code:
     Field field = theClass.class.getDeclaredField("theField");
     field.setAccessible(true);
    Now theField, a member of theClass is, in effect, public.

    Albert:rolleyes:

  3. #3
    Marcus is offline Member
    Join Date
    Jun 2007
    Posts
    92
    Rep Power
    0

    Default RE: Question of private member

    I'd also add that in almost all circumstances, it's also a bad idea. Reflection can be abused to break encapsulation, which is one of the fundamental principles of good Object-oriented programming and design.
    Greetings.

    Marcus:cool:

Similar Threads

  1. How to implement private chat application using jsp
    By PortalTeam in forum JavaServer Pages (JSP) and JSTL
    Replies: 9
    Last Post: 02-19-2010, 11:49 PM
  2. hi every body...new member here
    By ali obeed in forum Java Applets
    Replies: 0
    Last Post: 03-03-2008, 11:13 PM
  3. new member-need help
    By vandana in forum New To Java
    Replies: 2
    Last Post: 01-21-2008, 07:01 AM
  4. Private main method
    By bugger in forum New To Java
    Replies: 1
    Last Post: 12-21-2007, 10:45 AM
  5. new member
    By riadmazloum in forum Introductions
    Replies: 1
    Last Post: 08-09-2007, 01:15 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
  •