quiz3_questions - EE322CDataStructures Spring2009...

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

View Full Document Right Arrow Icon
EE 322C Data Structures   Spring 2009   Dr.Ramesh Yerraballi   Quiz 3 Due: Wed 3/15 in class                                                                                       Total points: 80 Name(First,Middle,Last):   Instructions:   Type in the answers to the questions in the space provided and turn in a hardcopy in class. {Feel free to  expand the answer space as needed} Attempt the questions by yourself first. Reading the material should help you with this. Don’t rely on the  computer to find your answer. Use it to improve and verify your understanding.   1. Answer with respect to the following snippet (10 points) class Sample {      static int i;      int j;      Sample(int i,int j)      {          this.i = i;          this.j = j;      }      public static void incrI()      {this.i++;}        public static void incrJ()      {this.j++;}      public int getJ()      {return j;}      public int getI()      {return this.i;} } a) What is wrong with the  incrI()  method? How will you fix it?
Background image of page 1

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

View Full DocumentRight Arrow Icon
b) What is wrong with the  incrJ()  method? How will you fix it? c) What is wrong with the  getI()  method? How will you fix it? d) After the fixes are in place, what is the output of the following code; ... Sample s1 = new Sample(1,2); s1.incrI();s1.incrJ(); Sample s2 = new Sample(3,4); s2.incrI();s2.incrJ(); System.out.println(s1.getJ() + ":" + s1.getI()); System.out.println(s2.getJ() + ":" + s2.getI()); ... e) If you are forbidden to initialize any of your static member variables inside any method of Sample, how else would  you initialize your static variables?  2. Answer with respect to the following code snippet [9 points]
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

quiz3_questions - EE322CDataStructures Spring2009...

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

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