
What is a trap?
public class BrowserTest {
public static void main(String[] args) {
System.out.print("iexplore:");
http://www.google.com;
System.out.println(":maximize");
}
}http: //www.google.com;


class Employee {
string _name;
string _dept;
public:
Employee(string name, string dept);
virtual void print() const { cout << _name << endl; }
string dept() const;
};
class Manager : public Employee {
public:
Manager(string name, string dept);
virtual void print() const {
print(); // print superclass
cout << "Managing " << dept() << endl;
}
};print() does not print the superclassEmployee::print()super.print()class Employee {
string _name;
string _dept;
public:
Employee(string name, string dept);
virtual void print() const { cout << _name << endl; }
string dept() const;
};
class Manager : public Employee {
public:
Manager(string name, string dept);
virtual void print() const {
Employee:print(); // print superclass
cout << "Managing " << dept() << endl;
}
};Employee:print();

class Shape {
Color _color;
public:
Shape() { reset(); }
virtual void reset() { _color = BLACK; }
};
class Point : public Shape {
double _x, _y;
public:
void reset() {
Shape::reset();
_x = 0; _y = 0;
}
};
Point constructor calls the Shape constructor...reset.reset?this->reset(), of course!this has type Shape* since the Point hasn't yet been constructed...Shape::reset.class Employee {
private String name;
public Employee(String name) {
this.name = name;
System.out.println("Constructing " + this);
}
public String toString() { return name; }
}
class Manager extends Employee {
private String dept;
public Manager(String name, String dept) {
super(name);
this.dept = dept;
}
public String toString() {
return super.toString() + " " + dept.substring(0, 3);
}
}Manager?new Manager("...", "Sales") calls Employee("...")toString in the print statementManager.toStringdept.substring yield a NPE 
template<typename T> class Array {
public:
Array(int size);
T& operator[](int);
// ...
};
int main() {
Array<double> a(10);
a[0] = 0; a[1] = 1; a[2] = 4;
a[3] = 9; a[4] = 16;
a[5] = 25; a = 36; a[7] = 49;
a[8] = 64; a[9] = 81;
// ...
} a[5] = 25; a = 36; a[7] = 49;a = Array<double>(36);

template<typename T> class Array {
T* _data;
int _size;
public:
explicit Array(int size)
: _size(size), _data(new T(size)) {}
T& operator[](int n) { return _data[n]; }
}
main() {
Array<double> a(10), b(10);
for (int i = 0; i < 10; i ++) { a[i] = b[i] = i + 1; }
for (int i = 0; i < 10; i ++) { cout << b[i] << " "; }
// 5 6 7 8 9 10 7 8 9 10
} _data(new T(size)) // should have been new T[size]new double(10) points to a single value (containing 1000)T* 
List<Integer> nums = new ArrayList<>();
List<String> strings = new ArrayList<>();
for (int i = 1; i < 10; i++) { nums.add(i); strings.add("s" + i); }
strings.remove("s3");
nums.remove(3);
strings?[s1, s2, s4, s5, s6, s7, s8, s9]nums[1, 2, 3, 5, 6, 7, 8, 9]remove method! 
vector<int> a = ..., b = ...;
int n = 42;
vector<int>::iterator p = find(b.begin(), a.end(), n);
// Does b contain n?
if (p != b.end()) { *p = -1; a.push_back(n); }
// If so, set it to -1 and add it to a
b.end()a to bfind operate on two iterators instead of a vector???int a[] = ...; int* p = find(a, a + size, n);
template<typename T> class Array {
T* _data;
int _size;
public:
explicit Array(int size)
: _size(size), _data(new T[size]) {}
~Array() { delete[] _data; }
T& operator[](int n) { return _data[n]; }
};
Array<int> a(10); Array<int> b(10); a = b; // b is destroyed, then a
operator=class Point {
private int x;
private int y;
public Point(int x, int y) { this.x = x; this.y = y; }
public boolean equals(Object other) {
return x == ((Point) other).x && y == ((Point) other).y;
}
}
Set<Point> points = new HashSet<>(); for (int i = 0; i < 1000; i++) points.add(new Point(i / 100, i % 10));
points.size() is 1000 (or close to it)hashCode when you define equals!Manager* to an Employee*:
void layoff(Employee* e) { cout << e->name() << " is fired!"; }
void fireThemAll(Employee es[], int n) {
for (int i = 0; i < n; i++) { cout << e[i].name() << " is fired!"; }
}
Manager uselessMiddleManagers[10]; fireThemAll(uselessMiddleManagers, 10);
Manager[] array can be converted to a Manager* (array-pointer duality)Manager* can be convered to a Employee* (superclass conversion)Employee es[] is the same as Employee* (array-pointer duality)
