J2EEOnline J2EE  

Java Questions 11 - 20  «Prev  Next»

Java Questions 19 - Access Modifiers

  1. What types of access modifiers can you use for local variables?
    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?
    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() ?
    The Thread class has a method called isAlive() that checks whether a thread is still active.
  4. What is a final argument?
    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?
    An abstract method is a method whose implementation is deferred to a subclass.
  6. What are the characteristics of an abstract method?
    An abstract method contains no functional code and has no method body.
  7. Can you have an abstract clalss with no abstract methods?
    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?
    An abstract method ends in a semicolon.
    abstract void draw(); 
  9. What is one difference between an abstract and non-abstract class?
    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?
    Abstract methods are meant to be overridden and must be implemented by a non-abstract subclass that extends the abstract class.