📄 equation2.java
字号:
package examples.inner;
/** A class definition to explore the use of local
* inner classes
*/
public class Equation2 {
private int equationInput;
/** An interface defining the result from an
* equation
*/
public interface Result {
public double getAnswer();
}
/** Constructor method
* @param ei the equation input
*/
public Equation2( int ei ) {
equationInput = ei;
}
/** Create the result of the equation for the given
* input values
* @param input1 the first equation input
* @param input2 the second equation input
* @return the result object
*/
public Result getResult( final int input1,
final int input2 ) {
final int[] localVar = { 2,6,10,14};
return new Result() {
private int normalField;
public double getAnswer() {
return (double) input1/input2
- equationInput
+ localVar[2]
- normalField;
}
// this is an instance initializer block
{
normalField = 2;
}
};
}
/** The test method for the class
* @param args not used
*/
public static void main( String[] args ) {
Equation2 e = new Equation2( 10 );
Result r = e.getResult( 33, 5 );
System.out.println( r.getAnswer() );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -