Results are out! Find what you need...fast. Get quick advice or join the chat
x

Unlock these great extras with your FREE membership

  • One-on-one advice about results day and Clearing
  • Free access to our personal statement wizard
  • Customise TSR to suit how you want to use it

help,java help urgently needed. pleasee help

Announcements Posted on
Rate your uni — help us build a league table based on real student views 19-08-2015
  1. Offline

    ReputationRep:
    help got a problem
    i got an exam tomorrow and was just wandering
    in a program if u have two attributes with different access modifiers- one private and one public, how would you define one of the attributes to break the encapsulation principle? sorry its a question i know is gonna come up
    my friend said:
    answer: make the attribute which is private, public. this is to modify the value of that attribute.
    please say he is right someone
    whats the answer??
  2. Offline

    ReputationRep:
    Yes, I'd say that is correct.

    The encapsulation principle is really exactly what it sounds - that each class should be encapsulated. This means that all attributes that don't absolutely need to be public shouldn't be, and that all classes should essentially manage and have exclusive access to their own attributes. Having a class attribute as public allows other external classes to modify its value, which breaks this principle. This might not be a problem in some cases and is sometimes used if the programmer doesn't want to have access methods (getX() and setX()), but can cause problems in some circumstances (e.g. where the value is restricted somehow - it could be set to an invalid value by another class).

    Hope this helps a little. Good luck with the exam
  3. Offline

    ReputationRep:
    (Original post by bones)
    Yes, I'd say that is correct.

    The encapsulation principle is really exactly what it sounds - that each class should be encapsulated. This means that all attributes that don't absolutely need to be public shouldn't be, and that all classes should essentially manage and have exclusive access to their own attributes. Having a class attribute as public allows other external classes to modify its value, which breaks this principle. This might not be a problem in some cases and is sometimes used if the programmer doesn't want to have access methods (getX() and setX()), but can cause problems in some circumstances (e.g. where the value is restricted somehow - it could be set to an invalid value by another class).

    Hope this helps a little. Good luck with the exam
    Thanks so much.. i know now to say make the attribute which is public, private.

Reply

Submit reply

Register

Thanks for posting! You just need to create an account in order to submit the post
  1. this can't be left blank
    that username has been taken, please choose another Forgotten your password?
  2. this can't be left blank
    this email is already registered. Forgotten your password?
  3. this can't be left blank

    6 characters or longer with both numbers and letters is safer

  4. this can't be left empty
    your full birthday is required
  1. By joining you agree to our Ts and Cs, privacy policy and site rules

  2. Slide to join now Processing…

Updated: December 15, 2005
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

New on TSR

Rate your uni

Help build a new league table

Poll
How do you read?
Quick reply
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.