Last active
December 19, 2021 10:15
-
-
Save sunmeat/65bf456b4feb699761c8 to your computer and use it in GitHub Desktop.
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.constructors; | |
import java.util.Arrays; | |
class Person { | |
String name; | |
String surname; | |
int age; | |
Person() { | |
this("Иван"); | |
} | |
Person(String n) { | |
this(n, "Иванов"); | |
} | |
Person(String n, String s) { | |
this(n, s, 25); | |
} | |
// main c-tor | |
Person(String n, String s, int a) { | |
name = n; | |
surname = s; | |
age = a; | |
} | |
Person(String n, int a) { | |
this(n, "Иванов", a); | |
} | |
void print() { | |
System.out.println(toString()); | |
} | |
public String toString() { | |
return "\n" + name + " " + surname + ", " + age + " лет\n"; | |
} | |
} | |
class Program { | |
public static void main(String[] args) { | |
Person people[] = { | |
new Person(), | |
new Person("Василий"), | |
new Person("Пётр", "Петров"), | |
new Person("Борис", "Борисов", 37), | |
new Person("Валерий", 48)}; | |
System.out.println(Arrays.asList(people)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment