11.07.2015 Views

AP Computer Science Homework Set 9 Classes and Constructors

AP Computer Science Homework Set 9 Classes and Constructors

AP Computer Science Homework Set 9 Classes and Constructors

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

P9E. Modify the TV class (P8C) to include a one-argument constructor for a TV.The argument for the constructor should be a Boolean representing whether or not theTV is on. Make the proper modifications in the HDTV <strong>and</strong> BWTV classes so thatmay use the one-argument constructor defined in TV. Finally, modify the TVDriverso that instances of an HDTV <strong>and</strong> BWTW objects are instantiated using the oneargumentconstructor. The output should be the same as in program P8C.By the end of the lesson students should be able to:a. State that method invocations <strong>and</strong> local variables are stored on the stack <strong>and</strong> that objects <strong>and</strong>its instance variables are stored on the heap.b. Explain why the heap is also known as the “Garbage Collectible Heap”.c. Write the Java code to construct an object using the keyword “new” (i.e. write a zeroargument AND one or more argument constructor for an object.)d. Write the Java code for overloaded object constructors.e. Explain that a programmer needs to explicitly write a zero argument constructor if a one ormore argument constructor is written by the programmer.f. Explain that every constructor up an inheritance hierarchy is run at the time an object of asubclass is created.g. Write the Java code to invoke an object’s superclass constructor (with no arguments or withone or more arguments.)h. Write the Java code to invoke an overloaded constructor from another constructor using thekeyword “this”.i. Explain the difference between life <strong>and</strong> scope for local variables.j. Explain the three ways to eliminate an object’s reference (i.e. make it eligible for GC.)Page 2<strong>AP</strong> <strong>Computer</strong> <strong>Science</strong> – HW <strong>Set</strong> 9 Programshttp://thecubscientist.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!