Things you should know for the Fall 2007 CS211 Midterm #2
You really should know everything from Midterm #1 as well, but we will focus on things taught after midterm one.
- Variables and References
- What is the difference between a primitive type and a reference type (be able to recognize each)
- Understand the difference between calling a method with a reference type versus a primitive type.
- How do changes inside the method affect each?
- Static variables and methods
- Understand how to create a static variable
- Understand how to create a static method
- Understand what you need to do to use a static variable versus a non-static variable
- Static variables can be called with or without an instance of the object
- Non-static (or instance variables) require an instance of the object be created and then used to access the variable
- Understand what you need to do to call a static method versus a non-staic method
- Understand that a static vairable is shared among all instances of a Class
- Linked Lists
- Understand the basic concepts of a linked list
- Know how to implement add, insert, remove, remove all
- Know how to traverse a linked list (how to visit and print every data object in the list in order)
- Know the same things for a circular linked list
- Know the same for a doubly linked list
- Stacks
- Know how the basic methods work (push, pop, peek)
- Know how to implement the basic methods using a List data structure like a Vector or ArrayList.
- Know how to implement the basic methods using an array
- Know what LIFO means
- Queues
- Know how the basic methods work (enqueue, dequeue)
- Know how to implement the basic methods using a List data structure like a Vector or ArrayList.
- Know how to implement the basic methods using an array (hint: doing this well requires a circular array!)
- Know what FIFO means
- Inheritance
- Understand the concept of inheritance and how to do it using Java
- Know how the constructors get called when classes inherit from each other
- Know how methods get called when classes inherit from each other
- Know what public, private, protected and blank (package) access are for both methods and attributes
- Understand "has-a" relationship versus the "is-a" relationship, and how to do both.
- Know what overriding a method means
- Know what a "final" method means you cannot override that method in a subclass
- Know that an "abstract" method means you MUST override the method in a subclass
- Polymorphism and Dynamic Binding
- How do you implement a polymorphic method
- When
an overridden method gets call from a superclass what happens?
Runtime type is checked and then the appropriate method is called
- Know what overloading a method is. Don't confuse this with overriding a method.. they are different!!!
- Iterators
- Know what an Iterator is and why you use it
- Sorted lists
- Know definition of sort key
- Know the definition of stable sort
- Know how the Comparable interface works
- Know how to implement a compareTo methods
Review Problems and Answers
Problems:
- Ch 5 - Linked Lists - Self Test #1, #4, exercises #4, #13, programming problem #4
- Ch 7 - Stacks - exercises 1, 2, 3, 4 (answer),
- Ch 7 - Stacks - programming problem 3, 4. Ch 8 queues - exercises 2, 3,4,7 (answer),
- Ch 9 - Inheritance, Dynamic Binding (polymorphism) - exercises 1, 10 and programming problem 1(answer)
Other Questions:
Inheritance
- How do I make a method that no one can override?
- If you create an abstract method in a class, does the class itself need to be abstract?
- If you create an abstract method in a class and another class extends that class, what must the child class do?
Polymorphism
- Write a class Clock that has a method getTime();
- Write a subclass of Clock, AnalogClock that returns the Hours/Mins when getTime is called
- Write a sublcass of Clock, AtomicCLock that returns the Hours/Mins/Seconds/Milliseconds when getTime is called
-
Write a test method that uses a Clock variable (Clock c;) and assigns
it to either an Analog or Atomic clock and calls getTime.
- This is using polymorphism to determine which method gets called