Last active
August 29, 2025 16:48
-
-
Save sunmeat/fcdbda50040ab881eec5 to your computer and use it in GitHub Desktop.
this example
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 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