本文主要是介绍chapter10——练习题——day14,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
一、
二、
三、
四、
五、
六、
七、
一、
二、
三、
四、
package chapter10.homework;/*** @author LuHan* @version 1.0*/
public class Homework03 {public static void main(String[] args) {CellPhone cellPhone = new CellPhone();cellPhone.testWork(new ICalculate() {@Overridepublic double work(double n1, double n2) {return n1+n2;}},10,8);}
}
interface ICalculate{public double work(double n1,double n2);
}
class CellPhone{public void testWork(ICalculate iCalculate,double n1,double n2){double result = iCalculate.work(n1, n2);System.out.println("运算后的结果"+result);}
}
五、
package chapter10.homework;/*** @author LuHan* @version 1.0*/
public class Homework04 {public static void main(String[] args) {
// A a = new A();
// a.f1();new A().f1();}
}
class A{private String NAME="私有";public void f1(){class B{private final String NAME="韩顺平教育";public void show(){System.out.println("NAME="+NAME+" 测试+"+A.this.NAME);}}B b = new B();b.show();}}
六、
七、
package chapter10.homework;/*** @author LuHan* @version 1.0*/
public class Homework06 {public static void main(String[] args) {Car car = new Car(60);car.getAir().flow();}
}
class Car{private double temperature;public Car(double temperature) {this.temperature = temperature;}class Air{public void flow(){if(temperature>40){System.out.println("空调吹冷气");}else if(temperature<0){System.out.println("空调吹暖气");}else {System.out.println("空调关闭");}}}public Air getAir(){return new Air();}
}
八、
标题一
package chapter10.homework;/*** @author LuHan* @version 1.0*/
public class Homework07 {public static void main(String[] args) {Color green = Color.GREEN;green.show();switch (green){case YELLOW :System.out.println("匹配到黄色");break;case RED:System.out.println("匹配到红色");break;case GREEN:System.out.println("匹配到绿色");break;default:System.out.println("未匹配到");}}
}
interface IMyinterface{public void show();
}
enum Color implements IMyinterface{RED(255,0,0),BLUE(0,0,255),BLACK(0,0,0),YELLOW(255,255,0),GREEN(0,255,0);private int redValue;private int greenValue;private int blueValue;Color(int redValue, int greenValue, int blueValue) {this.redValue = redValue;this.greenValue = greenValue;this.blueValue = blueValue;}@Overridepublic void show() {System.out.println("属性值为:("+redValue+","+greenValue+","+blueValue+")");}
}
这篇关于chapter10——练习题——day14的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!