/DefaultMethodsExample.java Secret
Created
December 11, 2017 16:32
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
/** | |
* SmartRadio enough smart which let you tune your | |
* favorite channel in louder and lower volumes | |
* Now added smartness of auto tuning channel | |
*/ | |
public interface SmartRadio { | |
//old declared methods | |
public void tuneChannel(float channelFrequency); | |
//old declared methods | |
public void increaseVolume(); | |
//old declared methods | |
public void decreaseVolume(); | |
//new method added | |
default public void autoTuneChannel() { | |
System.out.println("auto tune channel feature added"); | |
} | |
} | |
/** | |
* ABC company has now launched their next smart {@link ABCAutoTuneRadio} | |
* which is type of SmartRadio but with added auto tune feature. | |
*/ | |
public class ABCAutoTuneRadio extends ABCRadio { | |
final float MIN_FREQ = 85.00F; | |
final float MAX_FREQ = 110.00F; | |
@Override | |
public void autoTuneChannel() { | |
for (float startFreq = MIN_FREQ; startFreq <= MAX_FREQ; startFreq += 1.0) { | |
tuneChannel(startFreq); | |
if (channel.isTuned()) { | |
break; | |
} | |
} | |
System.out.println("channel auto tuned to : " + getFrequency()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment