Skip to content

Instantly share code, notes, and snippets.

@karanmalhi
Created June 23, 2011 17:38
Show Gist options
  • Save karanmalhi/1043080 to your computer and use it in GitHub Desktop.
Save karanmalhi/1043080 to your computer and use it in GitHub Desktop.
Anonymous inner class example
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