Skip to content

Commit

Permalink
6.1. Вложенные классы: Внутренние классы;
Browse files Browse the repository at this point in the history
  • Loading branch information
Temzor committed Nov 28, 2023
1 parent 2077e96 commit fde66a3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/java/ru/j4j/oop/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ru.j4j.oop;

public class Car {
private String brand;
private String model;

public Car(String brand, String model) {
this.brand = brand;
this.model = model;
}

public void startEngine() {
System.out.println("Двигатель запущен");
}

public class Transmission {

public void accelerate() {
System.out.println("Ускорение");
}

}

public class Brakes {

public void brake() {
System.out.println("Торможение");
}

}

public class TripComputer {

public String tripData = "Бортовой компьютер";
private String model = "Модель TripComputer";

public void getInfo() {
System.out.println("Модель TripComputer: " + this.model);
System.out.println("Модель Car: " + Car.this.model);
}
}
}
14 changes: 14 additions & 0 deletions src/main/java/ru/j4j/oop/CarMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ru.j4j.oop;

public class CarMain {
public static void main(String[] args) {
Car car = new Car("Марка", "Модель");
Car.Transmission transmission = car.new Transmission();
Car.TripComputer tripComputer = car.new TripComputer();
Car.Brakes brakes = car.new Brakes();
car.startEngine();
transmission.accelerate();
brakes.brake();
tripComputer.getInfo();
}
}
10 changes: 10 additions & 0 deletions src/main/java/ru/j4j/oop/OuterClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ru.j4j.oop;

public class OuterClass {
class NestedClass {
}

static class StaticNestedClass {
}

}

0 comments on commit fde66a3

Please sign in to comment.