CSC 8310   Linguistics of Programming Languages
Dr. David Matuszek
Fall 1997, Villanova University

Java quiz

  1. What Java keyword is used to:
    1. tell a class to inherit from a previously defined class?  extends
    2. commit to defining methods defined in an abstract class?  implements
    3. enclose a block of code that might throw an exception?  try
    4. enclose a block of code that handles that exception?  catch (not final!)
    5. declare a variable to be a class variable rather than an instance variable?  static
    6. declare that a function does not return a value?  void
    7. refer to an object within a method of that same object?  this
    8. declare a variable that holds a single Unicode character?  char

  2. What is the difference between an application and an applet?
    An application is a complete program. An applet is a partial program; it requires an applet viewer to serve as a main program.
    
    
    
  3. What is the difference between a String and a StringBuffer?
    A String is a constant; a StringBuffer can be modified.
    
    
    
  4. Which (one) package should you import in order to get the classes Button, Panel, Component, and Graphics?
    java.awt
    
    
    
  5. What do you do to override a method?
    Define a method in a subclass that has the name, number of parameters, and parameter types as a method in its superclass.
    
    
    
  6. What do you do to overload a method?
    Define a method with the same name as existing method, but different parameters; or define a method with the same name and parameters, but in a different class.
    
    
    
  7. The following code defines a class ComplexNumber. Write a two-argument constructor for this class that assigns values to its two instance variables.
    class ComplexNumber {
      float re, im;
    
    public ComplexNumber (float re, float im) { this.re = re; this.im = im; } }