Java Questions 11 - 20  «Prev  Next»

Java Questions 19 - Access Modifiers

  1. What types of access modifiers can you use for local variables?

    Answer:
    The only access modifier you can use for local variables (variables within a method) is final .
    Once a local variable has been assigned a value, it can only be assigned another value if it is not final.

  2. What is the purpose of declaring a method as final?

    Answer:
    The final keyword prevents a method from being overridden in a subclass, and is often used to enforce the API functionality of a method.

  3. What is the purpose of the thread method isAlive() ?

    Answer:
    The Thread class has a method called isAlive() that checks whether a thread is still active.

  4. What is a final argument?

    Answer:
    public Record getRecord(int fileNumber, final int recNumber){}
    

    In this example, the variable recNumber is declared as final, which of course means it can not be modified within the method.
    A final argument must keep the same value that the parameter had when it was passed into the method.

  5. What is an abstract method?

    Answer:
    An abstract method is a method whose implementation is deferred to a subclass.

  6. What are the characteristics of an abstract method?

    Answer:
    An abstract method contains no functional code and has no method body.

  7. Can you have an abstract clalss with no abstract methods?

    Answer:
    Yes. You can have an abstract class with no abstract methods.
    public abstract class LegalClass{
      void goodMethod(){
      }
    } 
    

  8. What does an abstract mehod end with?

    Answer:
    An abstract method ends in a semicolon.
    abstract void draw(); 
    

  9. What is one difference between an abstract and non-abstract class?

    Answer:
    A non-abstract class is a class that can be instantiated. An abstract class can not be instantiated.

  10. What is the purpose of an abstract class?

    Answer:
    Abstract methods are meant to be overridden and must be implemented by a non-abstract subclass that extends the abstract class.