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

Info icon This 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 ____ Without changing the method header, stepCount() may be changed to contain a return statement.
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern