Java Questions 31 - 40  «Prev  Next»

Java Questions 39

  1. What is the correct way to access a static method (or static variable) ?
    Answer:
    The way to access a static method (or static variable) is to use the dot operator on the class name.
  2. Can a static method access an instance variable?
    Answer:
    A static method cannot access an instance variable or member field.
  3. Can a static method access a non-static method?
    Answer:
    A static method cannot access a non-static method because the non-static method is dependent on an instance.
  4. What does a static method have access to?
    Answer:
    A static method can access a 1) static method or 2) instance variable.
  5. Why can't static methods be overridden?
    Answer:
    Because anything static belongs to the class.


  6. What do the two concepts coupling and cohesion deal with?
    Answer:
    The 2 topics coupling and cohesion have to do with the quality of an Object Oriented Design.
  7. How can one describe coupling?
    Answer:
    Coupling is the degree to which one class knows about another class.
  8. Of the 2 types of coupling, which coupling is desirable?
    Answer:
    Loose coupling is desirable and tight coupling is undesirable.
  9. How would you define 2 classes that are loosely coupled?
    Answer:
    If the only knowledge that class A has about class B, is what class B has exposed through its interface,
    then class A and class B are said to be loosely coupled.
  10. What does the term cohesion define?
    Answer:
    The term cohesion is used to indicate the degree to which a class has a single, well-focused purpose.