Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Couple of Java OOP questions..

Options
  • 10-05-2009 6:50pm
    #1
    Registered Users Posts: 2,234 ✭✭✭


    Hi,

    I'm doing a bit of revision for my exam and there are a couple of small questions I can't seem to figure out. I think I have them correct i'm just looking for some confirmation..

    1)
    How does an instance data value differ from a class data value?
    An instance data value is a value that is stored in relation to the object(instance of a class) - many objects can be created from one class all having different values for instance data values. A class data value only stores 1 value and is available to all objects of that class. If one object changes the class value it is relected to all objects of that class.

    2)
    Which of the following would be the best choice to make a class variable (as opposed to an
    instance variable) of the class Person? Why?
    a) averageLifeExpectancy
    b) age
    c) gender
    d) typeOfCarDriven
    I'm thinking any of the first 3. I say this because any of those attributes are attributes of a person..not all people drive cars. I don#t remember the answer that the lecturer gave but I do remember not understanding the reason.

    3)
    To import a package named tools located in directory, ./packages/ what code would one have
    to write?

    I think that this is either a typo (the '.' shouldn't be there) or else it's a trick question. The command to answer the question would be
    import ..packages.tools.*;
    but this obviosuly throws an error about floats or something. Since a fullstop is a valid directory name in windows anyway maybe there is a way to use it in java?

    Any opinions on my answer esp the last one..thanks.


Comments

  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    for question two, the average life expectancy would be the best.

    for question three, it is not a typo, ./ just means from the current directory. so in the current directory there's a folder called packages and inside that a folder called tools.

    import packages.tools.*;

    is the line you would want.


  • Registered Users Posts: 2,234 ✭✭✭techguy


    for question two, the average life expectancy would be the best.

    for question three, it is not a typo, ./ just means from the current directory. so in the current directory there's a folder called packages and inside that a folder called tools.

    import packages.tools.*;

    is the line you would want.

    Thanks.. why would you choose average life expectancy?

    I'm assuming I was spot on with question 1 then?


  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    I'd choose the life expectancy variable because the rest can be tied to a single object.

    life expectancy is somethings that doesn't really tie to a person object as much as the others. i'm sure there are better ways to explain it...

    question one is spot on, perhaps mention that the keyword static is usually used for class variables.


  • Closed Accounts Posts: 6,151 ✭✭✭Thomas_S_Hunterson


    techguy wrote: »
    Thanks.. why would you choose average life expectancy?

    Average life expenctancy is the same for all people.

    Age and gender is not.
    /edit:too slow :o


  • Registered Users Posts: 981 ✭✭✭fasty


    Average life expectancy is something that's going to be the same for everyone. It's not instance data.


  • Advertisement
  • Registered Users Posts: 2,234 ✭✭✭techguy


    Now I remember that was the reason..

    My response was the averageLifeExpextancy is not the same for all people, technically speaking.

    Doesn't that figure vary for different parts of the world?
    < http://en.wikipedia.org/wiki/Life_expectancy#Variation_in_the_world_today >


  • Registered Users Posts: 2,234 ✭✭✭techguy


    fasty wrote: »
    Average life expectancy is something that's going to be the same for everyone. It's not instance data.

    I suppose, for a person from whatever region, aking my view into account.


  • Closed Accounts Posts: 6,151 ✭✭✭Thomas_S_Hunterson


    techguy wrote: »
    I suppose, for a person from whatever region, aking my view into account.

    No, technically your view is irrelevant:P

    The average life expectancy is simply that. The average age of death (/edit: or at least an estimate of) of every male and female on the planet.

    If you want to talk about the life expectancy of a specific country or race you can do that seperately.


  • Registered Users Posts: 2,234 ✭✭✭techguy


    Sean_K wrote: »
    No, technically your view is irrelevant:P

    The average life expectancy is simply that. The average age of death (/edit: or at least an estimate of) of every male and female on the planet.

    If you want to talk about the life expectancy of a specific country or race you can do that seperately.

    Agreed, its the average!


  • Registered Users Posts: 1,916 ✭✭✭ronivek


    It depends on how fine-grained you might ever want that value to be; but in the interest of reducing data duplication it should probably never be an instance variable at any rate.


  • Advertisement
Advertisement