INHERITANCE
In Lab 3, you modified several methods in the SList
class so that a "tail" reference could keep track of the end of the list, thereby speeding up the insertEnd()
method.
In Lab 3, you modified several methods in the SList
class so that a "tail" reference could keep track of the end of the list, thereby speeding up the insertEnd()
method.
Java stores stuff in two separate pools of memory: the stack and the heap.
The heap stores all objects, including all arrays, and all class variables (i.e. those declared "static").
The stack stores all local variables, including all parameters.
Let's consider two different data structures for storing a list of things: an array and a linked list.
An array is a pretty obvious way to store a list, with a big advantage: it enables very fast access of each item. However, it has two disadvantages.
while
LoopsA while
statement is like an if
statement, but the body of the statement is executed repeatedly, as long as the condition remains true. The following example tests whether n is a prime number by attempting to divide it by every integer in the range 2...n - 1.
Not all variables are references to objects. Some variables are primitive types, which store values like "3", "7.2", "h", and "false". They are:
An object is a repository of data.
amanda
is a Human
object. Then amanda.introduce()
is a method call, and amanda.age
is a field. Let's write a class definition for the Human
class.Cast of characters.
Given a set of N objects.
Lecture notes of CS 61B