This file contains hidden or 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
| package com.alex.encapsulation; | |
| class Cat { | |
| // поля: | |
| private String name; // кличка кота | |
| private String color; // цвет (масть) | |
| private int age; // возраст в годах | |
| private double weight; // вес |
This file contains hidden or 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
| package com.alex.static; | |
| class Location { | |
| int totalCount; | |
| class Monster { | |
| int health; | |
| int attack; |
This file contains hidden or 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
| package com.alex.static; | |
| // клас, що представляє монстра з характеристиками та лічильником екземплярів | |
| class Monster { | |
| // статичне поле для підрахунку створених монстрів | |
| private static int count = 0; | |
| private int health; // здоров'я монстра | |
| private int attack; // сила атаки монстра | |
| private int mana; // запас мани монстра |
This file contains hidden or 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
| package pack; | |
| class Student { | |
| static String academy = "IT Step"; | |
| int name; | |
| double avgRating; | |
| } | |
| class AudiCar { | |
| static String brand = "Audi"; |
This file contains hidden or 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
| package com.alex.static; | |
| class Monster { | |
| private static int count; | |
| private int health; | |
| private int attack; | |
| public Monster() throws Exception { |
This file contains hidden or 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
| package com.alex.static; | |
| class Algorithm { | |
| public static double pi = 3.14159; | |
| public static int Factorial(int x) { | |
| if (x == 1) { | |
| return 1; | |
| } else { |
This file contains hidden or 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
| package com.alex.static; | |
| // клас для демонстрації статичних блоків ініціалізації | |
| class StaticFields { | |
| // статичне поле з початковим значенням | |
| private static int a = 3; | |
| // статичне поле без початкового значення | |
| private static int b; | |
| // нестатичне поле | |
| private int c; |
This file contains hidden or 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
| package com.alex.static; | |
| class LoggerSingleton { | |
| private static LoggerSingleton instance = null; | |
| private int logCount = 0; | |
| private LoggerSingleton() { | |
| // nothing to do here :) | |
| } |
This file contains hidden or 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
| package com.alex.collections; | |
| class MyArrayList { | |
| private int size = 0; | |
| private int capacity = 10; | |
| private int[] data; | |
| public MyArrayList() { | |
| // data = new int[capacity]; // замість копіювання коду - застосовується делегування конструкторів! |
This file contains hidden or 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
| package collections; | |
| class SinglyLinkedList { | |
| class Node { | |
| int data; | |
| Node next; | |
| Node(int data) { | |
| this.data = data; |