Java Questions 39
- 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.
- Can a static method access an instance variable?
Answer:
A static method cannot access an instance variable or member field.
- 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.
- What does a static method have access to?
Answer:
A static method can access a 1) static method or 2) instance variable.
- Why can't static methods be overridden?
Answer:
Because anything static belongs to the class.
- 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.
- How can one describe coupling?
Answer:
Coupling is the degree to which one class knows about another class.
- Of the 2 types of coupling, which coupling is desirable?
Answer:
Loose coupling is desirable and tight coupling is undesirable.
- 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.
- 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.