Created
April 4, 2025 18:42
-
-
Save thinkphp/3647ae2f848a380391d50aeb06f09d40 to your computer and use it in GitHub Desktop.
agregare
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
class Address { | |
private String strada; | |
private String oras; | |
private String codPostal; | |
public Address(String strada, String oras, String codePostal) { | |
this.strada = strada; | |
this.oras = oras; | |
this.codPostal = codePostal; | |
} | |
@Override | |
public String toString() { | |
return "Adresa: " + strada + ". " + oras + ", " + codPostal; | |
} | |
} | |
class Student { | |
private String nume; | |
private Address adresa;//agregare | |
public Student(String nume, Address adresa) { | |
this.nume = nume; | |
this.adresa = adresa; | |
} | |
@Override | |
public String toString() { | |
return "Student: " + nume + ", " + adresa; | |
} | |
} | |
public class Agg { | |
public static void main(String[] args) { | |
Address address1 = new Address("Street ABC","Zurich","1234"); | |
Address address2 = new Address("Street XYZ","Amsterdam","6789"); | |
Student student1 = new Student("John", address1); | |
Student student2 = new Student("Maria", address2); | |
System.out.println(student1); | |
System.out.println(student2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment