The date is Nov 17, the time is 11:23am. Homework Three posted. Homework One turned in. Most people working on Homework Two. Not as many taking advantage of the office hours or lab. http://silo.cs.indiana.edu:8346/cgi-bin/fall2009/schedule Deadlines for turning in homework are flexible. There will be a test on Thu on Homework One and Homework Two. This could stand for the actual turning in of Homework One and Two if you have not turned them in already: you will get two problems randomly selected from the 3 + 8 in the two assignments. So prepare them, come prepared to work them out. So I will post the solutions to these 11 problems tonight and you can study them and ask questions and come prepared to defend two of them except you don't know which. If you have questions (about the exam) e-mail me: dgerman@indiana.edu If you can't take the test on Thu you should take it through the appointments any day between Wed Nov 18 and Tue Nov 24 which is next Tue. We will have a class on Tue Nov 24. Things that you should be familiar with: numbers, strings, expressions, variables of various types, assignment statements, if statements, loops, methods. Java programs are made out of classes. There is a special method where the program starts: public static void main(String[] args) { ... } Every class has a blueprint. Every class is a container. It contains the blueprint and static members. By members we mean variables and methods. The blueprint also contains members, they are not static -- we call them instance members. 1. The class extension mechanism, inheritance, polymorphism, dynamic method lookup. 2. I would also like to talk about interfaces and abstract classes. So I start by creating a file (call it Violin.java) with this content: class Horse { } class Story { public static void main(String[] args) { Horse a, b; a = new Horse(); b = new Horse(); System.out.println(a); System.out.println(b); } } You compile this with javac Violin.java and that creates two classes. The classes it creates are Horse.class and Story.class so you run Story: java Story You can run any class that has a main in it, in this case only Story has. We change the code a bit: class Horse { void talk() { System.out.println("Howdy."); } } class Story { public static void main(String[] args) { Horse a, b; a = new Horse(); b = new Horse(); a.talk(); b.talk(); } } So everybody has seen a horse and we all find it hard to describe it completely that's why we don't do exactly that today. But we can say that a Horse is a collection of features: data + methods (behaviors). Horse = { ... } What is a Unicorn? Unicorn = Horse U { Horn } The class extension mechanism is the set union of features. Thus a unicorn is a set of features: all the features in a horse plus a horn. {1, 2, 3} U {1, 3, 7} = {1, 2, 3, 5, 7} That's the set union. So we use the class extension mechanism for the first time: class Horse { void talk() { System.out.println("Howdy."); } } class Unicorn extends Horse { void sing() { System.out.println("I am singing..."); } } class Story { public static void main(String[] args) { Horse a, b; Unicorn c; a = new Horse(); a.talk(); c = new Unicorn(); c.talk(); c.sing(); } } Now we change the code a little to illustrate polymorphism: class Horse { void talk() { System.out.println("Howdy."); } } class Unicorn extends Horse { void sing() { System.out.println("I am singing..."); } } class Story { public static void main(String[] args) { Horse a, b; Unicorn c; b = new Unicorn(); b.talk(); System.out.println("--------------------"); a = new Horse(); a.talk(); c = new Unicorn(); c.talk(); c.sing(); } } So Safa brought this up: class Horse { void talk() { System.out.println("Howdy."); } } class Unicorn extends Horse { void sing() { System.out.println("I am singing..."); } } class Story { public static void main(String[] args) { Horse b; b = new Horse(); b.talk(); b.sing(); // won't work because a Horse can't sing } } This raises the class Horse { void talk() { System.out.println("Howdy."); } } class Unicorn extends Horse { void sing() { System.out.println("I am singing..."); } void talk() { System.out.println("Bonjour."); } } class Story { public static void main(String[] args) { Horse a = new Horse(); a.talk(); Horse b = new Unicorn(); b.talk(); } } Do you understand the outcome of this program?