E
E
EarthFM2014-07-08 11:59:53
Java
EarthFM, 2014-07-08 11:59:53

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

2 answer(s)
V
vlad20012, 2014-07-08
@vlad20012

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.

G
GavriKos, 2014-07-08
@GavriKos

I can't understand the entry private Human human

This is a member of the House class with type Human
We assigned the previously created student object to the houseOwner variable. If I remember the java correctly, then now the same is stored in houseOwner as in student, i.e. copy. But changing one does not change the other.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question