-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
6.1. Вложенные классы: Внутренние классы;
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} | ||
|
||
} |