Skip to content

Instantly share code, notes, and snippets.

@sunmeat
Last active August 29, 2025 16:48
Show Gist options
  • Select an option

  • Save sunmeat/fcdbda50040ab881eec5 to your computer and use it in GitHub Desktop.

Select an option

Save sunmeat/fcdbda50040ab881eec5 to your computer and use it in GitHub Desktop.
this example
package com.alex.encapsulation;
class Person {
Person ref = this;
String name;
String surname;
int age;
Person(String name, String surname, int age) {
// name = name; // "мантричний" код???
this.name = name;
this.surname = surname;
this.age = age;
}
void print() {
// System.out.println(name + " " + surname + ", " + age + " років");
System.out.println(this); // System.out.println(ref);
// this = new Person(); // cannot assign a value to final variable this!
}
}
class Program {
public static void main(String[] args) {
Person p = new Person("Олександр", "Загоруйко", 36);
System.out.println(p);
p.print();
// Person.print(p);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment