CSCI 1100 REVIEW

A page for questions and answers for the CSCI1100 exam review!

  • Q: What is a method header and what is a method definition? A: The method header or declaration is the signature of a method and includes the visibility modifier, return type, method name, parameter list and throws clause for exceptions. For example:

    public int fibonacci(int n) throws Exception 
    The definition of a method on the other hand, is the signature of a method plus its "body", that is the actual implementation of the method. For example:
    public int fibonacci(int n) throws Exception
    {
        if(n < 0) throw new Exception("n may not be smaller then 0!");
        else if (n <= 1) return n;
        else return fibonacci(n-1) + fibonacci(n-2);
    }