t1sp04sol

t1sp04sol - CS100J 2004 Spring Prelim 1 Solutions Question...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Question 1: (25 points) Part (a): (7 points) Write in the box on the right the output that will be produced by executing the following program. n is 7 p is 1 w is 1 n is 3 p is 6 Output CS100J 2004 Spring Prelim 1 Solutions public class Q1a { public static void main(String[] args) { int n=3, p=6; int w= junk(p); System.out.println(“w is ” + w); System.out.println(“n is ” + n); System.out.println(“p is ” + p); } public static int junk(int n) { int p=1; n= n + p; System.out.println(“n is ” + n); System.out.println(“p is ” + p); return p; } } Part (b): (18 points) Consider class Counter below. public class Counter { private int tally; public int getTally() { return tally; } public void stepCount() { tally= tally + 1; } public static void showName() { System.out.println(“Class Counter”); } public void funTally1(int t) { tally= t; } public void funTally2(int t) { this.tally= t; } public void funTally3(int tally) { this.tally= tally; } public void funTally4(int tally) { tally= tally; } } For each sentence below, indicate whether it is correct by writing true ” or “ false ” on the blank: ___false _ Variable tally is a class variable. _true ____ Variable tally is an instance variable. _true ____ Variable tally is a field. ___false _ Method getTally() is a procedure. _true
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/01/2008 for the course CS 100 taught by Professor Fan/vanloan during the Fall '07 term at Cornell.

Page1 / 4

t1sp04sol - CS100J 2004 Spring Prelim 1 Solutions Question...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online