package oop4;public class as {\x05static class VolcanoRobot {\x05\x05String status;\x05\x05int speed;\x05\x05float temperature;\x05\x05void checkTemperature() {\x05\x05\x05if (temperature > 660) {\x05\x05\x05\x05status = "returning home";\x05\x05\x05

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/27 13:26:07
package oop4;public class as {\x05static class VolcanoRobot {\x05\x05String status;\x05\x05int speed;\x05\x05float temperature;\x05\x05void checkTemperature() {\x05\x05\x05if (temperature > 660) {\x05\x05\x05\x05status =

package oop4;public class as {\x05static class VolcanoRobot {\x05\x05String status;\x05\x05int speed;\x05\x05float temperature;\x05\x05void checkTemperature() {\x05\x05\x05if (temperature > 660) {\x05\x05\x05\x05status = "returning home";\x05\x05\x05
package oop4;
public class as {
\x05static class VolcanoRobot {
\x05\x05String status;
\x05\x05int speed;
\x05\x05float temperature;
\x05\x05void checkTemperature() {
\x05\x05\x05if (temperature > 660) {
\x05\x05\x05\x05status = "returning home";
\x05\x05\x05\x05speed = 5;
\x05\x05\x05}
\x05\x05}
\x05\x05void showAttributes() {
\x05\x05\x05System.out.println("Status:" + status);
\x05\x05\x05System.out.println("Speed:" + speed);
\x05\x05\x05System.out.println("Temperature:" + temperature);
\x05\x05}
\x05\x05public static void main(String args[]) {
\x05\x05\x05VolcanoRobot dante = new VolcanoRobot();
\x05\x05\x05dante.status = "exploring";
\x05\x05\x05dante.speed = 2;
\x05\x05\x05dante.temperature = 510;
//从这开始请问是怎么执行的?
\x05\x05\x05dante.showAttributes();
\x05\x05\x05System.out.println("Incresing speed to 3.");
\x05\x05\x05dante.speed = 3;
\x05\x05\x05dante.showAttributes();
\x05\x05\x05System.out.println("Changing temperature to 670.");
\x05\x05\x05dante.temperature = 670;
\x05\x05\x05dante.showAttributes();
\x05\x05\x05System.out.println("Checking the temperature.");
\x05\x05\x05dante.checkTemperature();
\x05\x05\x05dante.showAttributes();
\x05\x05}
\x05}
}

package oop4;public class as {\x05static class VolcanoRobot {\x05\x05String status;\x05\x05int speed;\x05\x05float temperature;\x05\x05void checkTemperature() {\x05\x05\x05if (temperature > 660) {\x05\x05\x05\x05status = "returning home";\x05\x05\x05
VolcanoRobot对象有三个全局变量status、speed、temperature.执行主函数时先实例化VolcanoRobot对象,然后给三个变量赋值.再后来调用showAttributes()方法输出变量的值.输出结果:
Status:exploring
Speed:2
Temperature:510.0
Incresing speed to 3.
Status:exploring
Speed:3
Temperature:510.0
Changing temperature to 670.
Status:exploring
Speed:3
Temperature:670.0
Checking the temperature.
Status:returning home
Speed:5
Temperature:670.0