One-page version suitable for printing.
Name and explain a reason why generics (such as generic packages in Ada or templates in C++) are a useful feature for a programming language to include.
Write the withdraw: method of our Account class so that the balance cannot drop below 0.
Say you want to add a unary instance method into Smalltalk's built-in Integer class called abs, which returns the absolute value of the Integer instance to which the method is applied. Write the definition of this method.
Name two significant and distinct differences between the object-oriented features of Java and Smalltalk. Do not address other differences, like their radically different syntax.
Consider the following Java program.
class A { int f() { return 1; } } class B extends A { int f() { return 0; } } class Main { public static void main(String[] args) { A a = new B(); System.out.println(a.f()); } }
Consider the following program.
class Ident { int f(int x) { return x; } int g(int x) { return f(f(x)); } } class Square extends Ident { int f(int x) { return x * x; } } class Main { public static void main(String[] args) { Ident a = new Ident(); Ident b = new Square(); Square c = new Square(); System.out.println(a.g(3) + " " + b.g(3) + " " + c.g(3)); } }
Draw the Listener pattern using an UML Class Diagram.