1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| public class Car { private String color; private static int wheelCount = 4; private int volume = 0; public Car(String color) { this.color = color; } public void startEngine() { System.out.println("Car is starting..."); } public static int getWheelCount(){ return wheelCount; } public static class Tire{ private double pressure; public Tire(double pressure) { this.pressure = pressure; } public void checkPressure() {
System.out.println("static method getWheelCount:" + getWheelCount()); System.out.println("Pressure: " + pressure + "(Car has " + Car.wheelCount + " wheels)"); } } public class Radio {
public void increaseVolume() { volume++; System.out.println(color +" Car radio Volume: " + volume); } public void startEngineFromRadio() { System.out.println("Car is checking:"); System.out.println("WheelCount:" + getWheelCount() + "(YES)"); startEngine(); } } public static void main(String[] args) {
Car.Tire t = new Car.Tire(5); t.checkPressure();
Car car = new Car("red"); Car.Radio radio = car.new Radio(); radio.increaseVolume(); radio.startEngineFromRadio(); } }
|