Week 17 - PowerPoint PPT Presentation

dezso
week 17 n.
Skip this Video
Loading SlideShow in 5 Seconds..
Week 17 PowerPoint Presentation
play fullscreen
1 / 6
Download Presentation
Week 17
121 Views
Download Presentation

Week 17

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Week 17 Compare & Contrast Simpson's Puzzle solutions 9 Marks [ ]

  2. This week…. • Take a look at a solution to week 15’s Simpson's puzzle. • What is good & what is bad? • How can we improve on this? • Given that Java in a nice OO language • Polymorphism • What would a more elegant solution look like?

  3. Remember references? String user_name = new String(“THE”); Pointer to point to string object (called a Reference in Java) Allocate Storage in memory for a String object Connect user_name

  4. Polymorphism! • A very handy OO concept • Any instance of a class which inherits from (extends) another can also be treated as an instance of that class. • Casting is the process of converting an object from one type to another • e.g. converting int to float • Can also be used with object references… • e.g. ((JButton)e.getSource()).setIcon(…)

  5. Casting Object References • In java, any instance is implicitly and transparently casted as necessary. • Provided that the transformation goes upwards the inheritance hierarchy

  6. Inheritance Hierarchies (Casting) Automatic