PPT Slide
CS100A Answers to Sample #1
Question 1. 3 points for each correct answer.
For each question, we list only the final
values of variables that change.
(a) 8 points. Class: a “model” or blueprint
for the objects (or instances) of the class; a class
defines the fields (or variables) and methods of
each object of the class.
(b) 8 points. Let c be any instance of class C. If field
or method x declared in C is private, x can be referenced
only in the code of class C; if protected, in class C or any
of its subclasses; if public, then in any code that can
(c) 8 points. A function is a method that performs some task
and returns a value. Instead of the keyword void, the type or
class of the return value is used. Example:
public int plus (int x, int y)
Question 3. 15 points. Here’s the body of drawCircle:
{g.drawOval(x-r,y-r,2*r,2*r);}
Question 4. (a) 5 points.
public class ContractEmployee extends Employee
{double dailyRate; // Daily rate of pay
double daysWorked; // Days worked in year
// Constructor: An employee with name n, d days of work,
public ContractEmployee(String n, int d, double s)
// Yield a description of the contract employee
public String toString();
{return “Contract employee “ + name + “ days ” +
daysWorked + “ rate “ + dailyRate + “ = “ + pay;
// Change number of days worked to n
public void changeDays(int n)
pay= dailyRate*daysWorked;