Answer the question
In order to leave comments, you need to log in
What is aggregation?
I can't understand with class aggregation in java.
There are Human and House classes, as well as the Main class. There are other classes, but I don't take them.
I can't understand the entry private Human human(What is it an object or a simple variable) and return human.getName();
Also in the Main class. Human houseOwner = student;(What was created here? )
package com.lesson;
public class House {
private Human human;
public Human getHuman() {
return human;
}
public void setHuman(Human human) {
this.human = human;
}
public String getOwnerNAme() {
return human.getName();
}
}
package com.lesson;
public class Human {
private static final String N_A = "N_A";
private final String name;
private int age;
public Human(String name) {
this.name = name;
System.out.println("No");
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
}
package com.lesson;
public class Main {
public static void main(String[] args) {
Human human = new Human("Ilya");
System.out.println(human.getName());
System.out.println("~~~~~~~~~~~~~");
Student student = new Student("Roma");
System.out.println(student.getName());
System.out.println("~~~~~~~~~~~~~~~");
House house = new House();
Human houseOwner = student;
house.setHuman(houseOwner);
System.out.println("Owner name " + house.getOwnerNAme());
System.out.println("~~~~~~~~~~~~~~~");
}
}
Answer the question
In order to leave comments, you need to log in
I wrote, I write and I will write the same answer - read smart books before asking such questions. Too lazy to read everything - look at the table of contents. There you will find your own questions and detailed answers to them. For your question is not even about Java, but about the very basics of programming in any language and with any paradigm.
I can't understand the entry private Human human
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question