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 { | |
static int count; // статическое поле, общее для всех будущих объектов класса | |
int health; | |
int attack; | |
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 { | |
// статический блок инициализации | |
// обычно располагается после объявления статических полей | |
// перед static не пишется public или private | |
// позволяет выполнять вычисления для инициализации | |
static { | |
System.out.println("статический блок инициализации 1"); |
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; | |
} | |
private Node head; |