Java Questions 11 - 20  «Prev  Next»

Abstract Classes Access Modifiers

  1. Can a method be marked as both 1) abstract and 2) final?

    Answer:
    No. To have a method marked as both 1) abstract and 2) final is a contradiction.

  2. Why can't a method be marked both abstract and private?

    Answer:
    An abstract method is intended to be overriden and a private method cannot be overridden. A method can never be marked both abstract and private.

  3. What does the abstract modifier indicate about a method?

    Answer:
    An abstract designation means the superclass does not know aything about how the subclass will implement the method.

  4. Why are the abstract and final modifiers opposites of each other?

    Answer:
    An abstract class is intended to be extended and a final class cannot be extended.

  5. Why can't a private method be marked abstract?

    Answer:
    Private methods cannot be marked "abstract" because
    1. private methods cannot be overridden.
    2. private methods cannot be inherited because their visibility is only within the class that defined the private method.

  6. Why can't an abstract modifier be combined with the static modifier?

    Answer:
    The abstract modifier can never be combined with the static modifier because an abstract method is a member of an abstract class, and abstract classes are intended to be overridden.

  7. What does the synchronized keyword indicate when applied to a method?

    Answer:
    The sycnrhonized keyword indicates that a method can be accessed by only one thread at a time.

  8. Can the synchronized keyword be applied to variables?

    Answer:
    No. The synchronized modifier can be applied only to methods.The synchronized modifier can not be applied to variables or classes.

  9. Which access control level can be placed in front of the synchronized modifier?

    Answer:
    The synchronized modifier can be matched with any of the four access control levels 1) public 2) private 3) protected and 4) default.

  10. In which context can native methods be applied?

    Answer:
    Native is a modifier that can only be applied to methods.
    A method that is native is implemented in platform-dependent code, typically written in another programming language such as C. The body of a native method is given as a semicolon only, indicating that the implementation is omitted, instead of a block.