Answer the question
In order to leave comments, you need to log in
Is it possible in this code to create another class with a method that would call the print() method to return values and how to write it?
class Person {
int age;
String name;
int height;
void print() {
System.out.println("Человек: " + "\nвозраст = " + age + " лет "
+ " \nимя " + name + " \nрост " + height + " см ");
}
}
class PersonTest {
public static void main(String[] args){
Person p1 = new Person();
Person p2 = new Person();
p1.age = 36;
p1.name = "Jack";
p1.height = 170;
p1.print();
p2.age = 25;
p2.name = "Poll";
p2.height = 150;
p2.print();
Answer the question
In order to leave comments, you need to log in
Make the person static class, preferably refactor the construction to this.name=name; and so on,
the method is void, so it cannot return anything. (Remove the void) and try using constructors (much more convenient this way)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question