Created
June 23, 2011 17:38
-
-
Save karanmalhi/1043080 to your computer and use it in GitHub Desktop.
Anonymous inner class example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.lq; | |
public class InnerClassExample { | |
public static void main(String[] args) { | |
Driver d = new Driver(); | |
Car c = new Car(); | |
d.operate(c); | |
d.operate( | |
// anonymous Inner class | |
new Driveable(){ | |
public void drive() { | |
System.out.println("Driving a truck.."); | |
} | |
} | |
); | |
} | |
} | |
class Driver{ | |
void operate(Driveable d) { | |
d.drive(); | |
} | |
} | |
interface Driveable { | |
void drive(); | |
} | |
class Car implements Driveable{ | |
public void drive() { | |
System.out.println("Driving a Car.."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment