Advertisement
RashedBQ

Java Aggregation

Mar 16th, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. package javaapplication2;
  2. class Address {
  3.  int postal;
  4.  String street;
  5.  String city;
  6.  String country;
  7.  
  8.  Address(int p,String s,String c,String co){
  9.  postal = p;
  10.  street = s;
  11.  city = c;
  12.  country =co;
  13.  }
  14.  
  15. }
  16.  
  17.  
  18. __________________________________
  19. class Employee {
  20.  int id;
  21.  String name;
  22.  double salary;
  23.  Address address;
  24.  
  25.  Employee(int i, String n,double s,Address a){
  26.  id = i;
  27.  name = n;
  28.  salary = s;
  29.  address = a;
  30.  }
  31.  
  32.  
  33. }
  34. public class JavaApplication2 {
  35.  public static void main(String[] args) {
  36.  
  37.  Address a = new Address(1234,"king fahad","riyadh","KSA");
  38.  
  39.  Employee e = new Employee(1,"Saleh",8000,a);
  40.  
  41.  
  42.  System.out.println("ID: "+e.id);
  43.  System.out.println("NAME: "+e.name);
  44.  System.out.println("SALARY: "+e.salary);
  45.  System.out.println("POSTAL: "+e.address.postal);
  46.  System.out.println("STREET: "+e.address.street);
  47.  System.out.println("CITY: "+e.address.city);
  48.  System.out.println("COUNTRY: "+e.address.country);
  49.  
  50.  }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement