rblog

“Aldri Kaffe, Aldri Golf”

This one is kind’a geeky, but I have to show it to you. I’m reading chapter three of my SCJP-book (Sun Certified Java Programmer) where I found this example (which won’t compile…it’s not meant to, it’s just an example 🙂 ) Read through the code, and pay special attention to the comments, I really like the last one

interface Sporty() {
	void beSporty();
}

class Ferrari extends Car implements Sporty {
	public void beSporty() {
		// implements cool sporty method 
		// in a Ferrari-specific way
	}
}
class RacingFlats extends AthleticShoe implements Sporty {
	public void beSporty {
		// implements cool sporty mehtod 
		// in a RacingShoe-specific way
}
class GolfClub { }
class TestSportyThings {
	public static void main (String[] args) {
		Sporty[] sportyThings = new Sporty[3];
		sportyThings[0] = new Ferrari(); 	
		// Ok, Ferrari implements Sporty
		sportyThings[1] = new RacingFlats(); 	
		// Ok, RacingFlats implements Sporty
		sportyThings[2] = new GolfClub();	
		// Not ok, GolfClub does not implement Sporty
		// I don't care what anyone says!!
	}
}

As some of you might know, I have a saying that goes like this “Never coffee, never golf”. I’m starting to like this book