汽车类有三个领域:
class Car {/* 来自 N o w J a v a . c o m - 时 代 Java*/ String status; int speed; float temperature; Car(String inStatus, int inSpeed, float inTemperature) { status = inStatus; speed = inSpeed; temperature = inTemperature; } void checkTemperature() { if (temperature < -80) { status = "returning home"; speed = 5; }// 来 自 时 代 J a v a } void showAttributes() { System.out.println("Status: " + status); System.out.println("Speed: " + speed); System.out.println("Temperature: " + temperature); } } public class Main { public static void main(String[] arguments) { Car spirit = new Car("exploring", 2, -80); spirit.showAttributes(); System.out.println("Increasing speed to 3."); spirit.speed = 3; spirit.showAttributes(); System.out.println(