Term
|
Definition
The is-a relationship between a more general superclass and a more specialized subclass. |
|
|
Term
|
Definition
A general class from which a more specialized class (a subclass) inherits |
|
|
Term
|
Definition
A class that inherits variables and methods from a superclass but adds instance variables, adds methods, or redefines methods |
|
|
Term
|
Definition
The principle that a subclass object can be used in place of any superclass object. |
|
|
Term
|
Definition
redefining a method in a subclass |
|
|
Term
|
Definition
Giving more than one meaning to a method name |
|
|
Term
|
Definition
Selecting a method to be invoked at run time. In Java, dynamic method lookup considers the class of the implicit parameter object to select the appropriate method. |
|
|
Term
|
Definition
Selecting a method among several methods that have the same name on the basis of the actual types of the implicit parameters |
|
|
Term
|
Definition
A value that is computed by a hash function |
|
|
Term
|
Definition
A type with no instance variables, only abstract methods and constants |
|
|
Term
implementing an interface |
|
Definition
Implementing a class that defines all methods specified in the interface |
|
|
Term
|
Definition
A class that is defined inside another class |
|
|
Term
Differences between an interface and an abstract class |
|
Definition
1) Interface has no data except constants, while an abstract class can have data members
2) An interface has no concrete methods, while an abstract class can have concrete methods for code reuse |
|
|
Term
Similarities between an interface and an abstract class |
|
Definition
1) Define responsibilities for implementers or subclasses
2) Can't be instantiated |
|
|
Term
Advantage of using an abstract class |
|
Definition
Can provide common data members and methods that you can reuse |
|
|
Term
Advantage of using an interface |
|
Definition
A class can only extend one class, but can implement multiple interfaces |
|
|
Term
How to reverse a linked list |
|
Definition
Node current = head;
while (current != null) { next = current.next; current.next = previous; previous = current; current = next; } head = previous; |
|
|
Term
What is a Comparator, how does it work, and what are its advantages over Comparable? |
|
Definition
-- Comparator is an interface for comparisons between two Objects -- public int compare (Object a, Object b) -- class FooComparatorA implements Comparator { int compare(f1, f2) {return f1.age - f2.age;} } -- More flexible to compare Objects in different ways (i.e., based on different data members) -- Comparators are different classes. If your class doesn't implement Comparable, you can still use a class that implements Comparator. |
|
|
Term
|
Definition
-- It's not strictly necessary -- At compile-time, it checks the function signatures with those of the parent class to verify that you are actually overriding something -- If you're not, you get an error -- If you don't add @Override, you could get some confusing behavior, like if you think the child is using its parent when it's really not |
|
|
Term
|
Definition
The child class includes an instance of the parent as a data member |
|
|
Term
Advantages of composition over inheritance |
|
Definition
1) Can combine multiple objects within, not restricted to inheriting only one class, or otherwise using inheritance hierarchy (ancestors)
2) You are not as vulnerable to changes in the parent class. If you only use a few methods from the parent class, then it's easier for you to know which parts of your code you need to change if the parent class changes. |
|
|
Term
The LinkedList class implements which interfaces? |
|
Definition
List, Collection, and Iterable |
|
|
Term
The ArrayList class implements which interfaces? |
|
Definition
List, Collection, and Iterable |
|
|
Term
The HashMap class implements which interface? |
|
Definition
|
|
Term
Example of an interface extending another interface |
|
Definition
Collection extends Iterable List extends Collection |
|
|
Term
|
Definition
public interface Comparable { public int compareTo(T other); } |
|
|
Term
How to evaluate compareTo |
|
Definition
If this > other, return positive if this == other, return 0 if this < other, return negative |
|
|
Term
Four things an interface can have |
|
Definition
1) Abstract methods 2) Static methods 3) Default methods 4) Constant data members |
|
|
Term
Constructor of a child class |
|
Definition
public childClass (parent parameter, parent parameter, child parameter) { super(parent parameter, parent parameter); param = child parameter; } |
|
|
Term
|
Definition
public return method () { super.method(); new stuff; } |
|
|
Term
|
Definition
public Foo (int x) { ... }
public Foo (int x, int y) { this(x); ... } |
|
|
Term
|
Definition
casting a subtype to a supertype Animal anim = (Animal) dog
void train (Animal animal) trainer.train(new Dog()) |
|
|
Term
|
Definition
We want general code applied only to the superclass type |
|
|
Term
|
Definition
casting to a subtype Animal doggy = new Dog() Dog doggytoo = (Dog) doggy |
|
|
Term
|
Definition
Animal doggy = new Dog(); if (doggy instanceof Dog) { Dog doggytoo = (Dog) doggy; } |
|
|
Term
Why is HashMap.get(key) O(1)? |
|
Definition
You do a hash function to find the key's index, or bucket. Just do a few operations -- like summing the characters in a String and then doing mod number of buckets -- and then go straight to that bucket |
|
|
Term
Time complexity of setting an element in a built-in array |
|
Definition
|
|
Term
|
Definition
the average cost of an operation over a sequence of such operations |
|
|
Term
Pros and cons of a linked list |
|
Definition
Fast to insert, slow to get to an index |
|
|
Term
|
Definition
When something is defined in terms of itself |
|
|
Term
|
Definition
The branch in which there is no recursive call |
|
|