Need Help with JAva?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thatos
    New Member
    • Aug 2007
    • 105

    Need Help with JAva?

    Can you please answer the following questions for me.
    a) I read a book which said that set of methods of a class defines its interface what those this mean?
    b)If you don't declare your method as public or private that those it take it to be i.e what is the default is it public or package or private?
    C)Why do sometimes people declare instance variables as private?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by thatos
    Can you please answer the following questions for me.
    a) I read a book which said that set of methods of a class defines its interface what those this mean?
    b)If you don't declare your method as public or private that those it take it to be i.e what is the default is it public or package or private?
    C)Why do sometimes people declare instance variables as private?
    a) the public methods of a class define what you (or all the others in the outer
    world) can do with an object of that class. The methods are the 'interface' of
    the class, The word 'interface' is used quite sloppy here because Java has
    a notion of an interface which you can define yourself.

    b) if you don't define your methods as public, protected or private these methods
    can only be used by others that are defined in the same package.

    c) They should always do so; exposing your member variables is considered flashing.

    kind regards,

    Jos

    Comment

    Working...