Skip to content

Commit

Permalink
6.3. Статические вложенные классы;
Browse files Browse the repository at this point in the history
  • Loading branch information
Temzor committed Nov 28, 2023
1 parent b09b2c6 commit 5568b03
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/ru/j4j/oop/Calc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ru.j4j.oop;

public class Calc {

public static class Multiple {

private final int rsl;

public Multiple(int number) {
rsl = number;
}

public int getResult() {
return rsl;
}

}

public static Multiple getMult(int value) {
int result = value * value;
return new Multiple(result);
}

public static void main(String[] args) {
Calc.Multiple mult = Calc.getMult(3);
System.out.println("Квадрат числа равен " + mult.getResult());
}
}
25 changes: 25 additions & 0 deletions src/main/java/ru/j4j/oop/StNested.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ru.j4j.oop;

public class StNested {

private static int num1;
public int num2;

public StNested() {
}

static class StaticNested {

void setStaticOuterVariable(int value) {
num1 = value;
}

}

public static void main(String[] args) {
num1 = 1;
StaticNested nested = new StaticNested();
nested.setStaticOuterVariable(2);
System.out.println("num1 = " + num1);
}
}

0 comments on commit 5568b03

Please sign in to comment.