Download presentation
Presentation is loading. Please wait.
1
In-class exercise 1
2
1.downloading Java http://developers.sun.com/downloads Java SE Java SE (JDK) 6 JDK 6u2 jdk-6u2-windows-i568-p.exe
3
2. Implementation of a java program import java.util.*; import java.lang.*; interface CanFight { void fight ( );} interface CanSwim { void swim ( );} interface CanFly {void fly ( );} class ActionCharacter { public void fight( ) { }} class Hero extends ActionCharacter implements CanFight, CanSwim, CanFly { public void fight ( ) {System.out.println(“Can fight!”);} public void swim ( ) {System.out.println(“Can swim!”); } public void fly ( ) {System.out.println(“Can fly!”);} }
4
public class Adventure { static void t(CanFight x) { x.fight();} static void u(CanSwim x) { x.swim();} static void v(CanFly x) { x.fly();} static void w(ActionCharacter x) { x.fight();} public static void main (String[ ] args) { Hero h = new Hero( ); t(h); //Treat it as a CanFight u(h); //Treat it as a CanSwim v(h); //Treat it as a CanFly w(h); //Treat it as an ActionCharacter }
5
To compile the Java program: RealJ BlueJ JCreator or NotePad use “Command Prompt” javac Adventure.java java Adventure
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.