CSC 8310 Linguistics of Programming Languages
Dr. David Matuszek
Fall 1997, Villanova University
Java quiz
What Java keyword is used to:
tell a class to inherit from a previously defined class?
extends
commit to defining methods defined in an abstract class?
implements
enclose a block of code that might throw an exception?
try
enclose a block of code that handles that exception?
catch (not final!)
declare a variable to be a class variable rather
than an instance variable?
static
declare that a function does not return a value?
void
refer to an object within a method of that same object?
this
declare a variable that holds a single Unicode character?
char
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.
What is the difference between a String and a
StringBuffer?
A String is a constant; a StringBuffer can be modified.
Which (one) package should you import in order to get the classes
Button, Panel, Component, and Graphics?
java.awt
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.
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.
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;
}
}