Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

can you explain public, private and static classes?

what other identifiers are valid for classes?

5 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    depends on the language..

    for C++ / C#:

    quoted

    " If a data member or method is public, that means that it can be accessed by anything outside of the object itself. It can be accessed directly by other objects.

    Private data members and methods can only be accessed by other functions / members inside of the function (whether they be public or private). Other objects can't access them directly (ignoring inheritance scenarios).

    When something is static, that means that each instance of the object shares that one thing. If it's a variable that has a value of 5, then every single object, when referencing this static member, will see the same value. And if one instance of the object modifies it, then all of the other instances that've been made can see the changes. It's shared between all of the instances.

    "

    link from old YA! answer.. "Anonymous_person 1337"

  • Anonymous
    1 decade ago

    I see this question has been answered, but I wish to make clearer answers for differences between Public, Private, and Static.

    Public: Available to anything that may call this class, so long as the variable that is being used is called in a Public sense.

    Example: I can create a Private instance of a public class and that won't be accessible to other classes if they are trying to go though my class.

    Private: Available only from within the current class. This may also be referred to a partial class or inner class. It inherits the rights of it's owner class, but no outer class may touch it.

    Example: I have an new Dog class, and in it I have a Breed class. I may make an instance of Dog, but not of Breed. The Breed class is exclusively owned by Dog.

    Static: Static implies "non-changeable", but more effectively "unique". There is one copy of this Static member and that is it. Static matters if you are trying to do something dynamic. You can't set the size of any array to be the result of some function. You can have dynamic size arrays, but you just have to be more specific in declaration.

    Example: I am getting an instance of Dog(getDog()); You can't do that if the class is static. You will have to do. Dog theDog = getDog();

  • 4 years ago

    They do fairly plenty what they sound like. once you have a classification in Java you could upload those key phrases to techniques or variables outdoors of a skill (those variables are called fields). the indoors maximum key-word skill which you will basically use the tactic/variable basically in the class. the regularly occurring public key-word skill which you will use the tactic/variable from the different classification. decrease than i've got lined only slightly code as an occasion public classification individual { inner maximum int age; public String call; } The variable call may well be utilized by the different classification however the variable age can basically be used in the guy classification.

  • Anonymous
    1 decade ago

    Public: accessible to the entire program within an object

    Private: accessible only to other functions/methods within that specific class

    Static: can be public, private or protected. This method/function can be accessible without the object being constructed or 'called'

    you can also have protected, in which the attribute or method/function is only accessible to that object and any inherited objects in which the containing class is the parent

  • How do you think about the answers? You can sign in to vote the answer.
  • 1 decade ago

    Yes.

Still have questions? Get your answers by asking now.