目录
一、
二、
三、
四、
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() {
@Override
public 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;
}
@Override
public void show() {
System.out.println("属性值为:("+redValue+","+greenValue+","+blueValue+")");
}
}