Last active
August 29, 2015 14:18
-
-
Save RuZman/a92b18e0502191906ebd to your computer and use it in GitHub Desktop.
This file contains 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
import java.util.Objects; | |
public class SubClass2 extends AClass { | |
public static void main(String[] args) { | |
System.out.println(new SubClass2(6).getValue1()); | |
} | |
public SubClass2(int value) { | |
super(new MyCalculation(value)); | |
} | |
private static class MyCalculation implements ICalc { | |
private int value; | |
public MyCalculation(int value) { | |
this.value = value; | |
} | |
@Override | |
public int getValue() { | |
return value + 10; | |
} | |
} | |
} | |
abstract class AClass { | |
private final int value1; | |
public AClass(ICalc calc) { | |
this.value1 = Objects.requireNonNull(calc.getValue()); | |
} | |
public final int getValue1() { | |
return value1; | |
} | |
} | |
interface ICalc { | |
int getValue(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment