Last active
December 19, 2021 10:14
-
-
Save sunmeat/4a58a925260e8f536147 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; | |
class Person { | |
String name; | |
String surname; | |
int age; | |
Person() { // конструктор без параметров | |
this("Иван", "Иванов", 25); | |
System.out.println("default constructor"); | |
} | |
Person(String n) { | |
this(n, "Иванов", 25); | |
System.out.println("params: string"); | |
} | |
Person(String n, String s) { | |
this(n, s, 25); | |
System.out.println("params: string, string"); | |
} | |
// main c-tor | |
Person(String n, String s, int a) { | |
// this(); // главное, тут комментарий не раскрыть :) | |
name = n; | |
surname = s; | |
age = a; | |
System.out.println("\nmain constructor!"); | |
} | |
Person(String n, int a) { | |
this(n, "Иванов", a); | |
System.out.println("params: string, int"); | |
} | |
void print() { | |
System.out.println(name + " " + surname + ", " + age + " лет."); | |
} | |
} | |
class Person { | |
public static void main(String[] args) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment