Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to access private variables of another class?

807580Sep 8 2010 — edited Sep 8 2010
So, I have the following class:
public class Person
{
        private String firstName;
        private String lastName;

        public Person()
        {
        }

        public Person(String first, String last)
        {
                this.firstName = first;
                this.lastName = last;
        }
}
I'm aware that if I make the variables 'protected' or 'public' rather than 'private', I'll be able to access them from another class without mutator/accessor methods. Given how the code is now, is it possible to access these private variables from another class without using the aforementioned methods? Any help would be greatly appreciated!

Thanks,
Mark
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 6 2010
Added on Sep 8 2010
8 comments
133 views