Last active
December 19, 2021 10:07
-
-
Save sunmeat/e5d2277b4a6337a5d467 to your computer and use it in GitHub Desktop.
finalize
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.destructors; | |
class Person { | |
String name; | |
String surname; | |
int age; | |
Person() { // конструктор без параметров | |
name = "Иван"; | |
surname = "Иванов"; | |
age = 30; | |
} | |
Person(int number) { | |
age = number; | |
} | |
Person(String n, String s, int a) { // конструктор с параметрами | |
name = n; | |
surname = s; | |
age = a; | |
} | |
void print() { | |
System.out.println(name + " " + surname + ", " + age + " лет."); | |
} | |
@Override | |
protected void finalize() throws Throwable { | |
super.finalize(); | |
System.out.println("Object #" + age); | |
} | |
} | |
class Program { | |
public static void main(String[] args) { | |
int count = 100000; | |
for (int i = 0; i < count; i++) { | |
Person p = new Person(i); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment