Last active
December 19, 2021 10:07
-
-
Save sunmeat/55a920e1bf8a3f7b1141 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() { // конструктор без параметров | |
name = "Иван"; | |
surname = "Иванов"; | |
age = 30; | |
} | |
Person(String n, String s, int a) { // конструктор с параметрами | |
name = n; | |
surname = s; | |
age = a; | |
} | |
void print() { | |
System.out.println(name + " " + surname + ", " + age + " лет."); | |
} | |
} | |
class Program { | |
public static void main(String[] args) { | |
Person a = new Person("Petr", "Petrov", 47); | |
Person b = new Person(); | |
a.print(); // Petr Petrov, 47 лет. | |
b.print(); // Иван Иванов, 30 лет. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment