SHARE
TWEET

Untitled

a guest May 22nd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3.  
  4. public class SampleOverload {
  5.     public static void main(String[] args) {
  6.         ArrayList<Obj> obj = new ArrayList<>(
  7.                 Arrays.asList(
  8.                         new Obj(),
  9.                         new Obj("佐藤"),
  10.                         new Obj("伊藤",41),
  11.                         new Obj("田中",23, "埼玉"))
  12.                 );
  13.         for(Obj o: obj) {
  14.             System.out.println("名前 : " + o.getName());
  15.             System.out.println("年齢 : " + o.getAge());
  16.             System.out.println("出身地 : " + o.getPlace());
  17.             System.out.println("----------------------");
  18.         }
  19.     }
  20. }
  21.  
  22. class Obj{
  23.     private String name;
  24.     private int age;
  25.     private String place;
  26.  
  27.     Obj(){
  28.         this.name = "NoName";
  29.         this.age = 20;
  30.         this.place = "日本";
  31.     }
  32.  
  33.     Obj(String name){
  34.         this.name = name;
  35.         this.age = 20;
  36.         this.place = "日本";
  37.     }
  38.  
  39.     Obj(String name, int age){
  40.         this.name = name;
  41.         this.age = age;
  42.         this.place = "日本";
  43.     }
  44.  
  45.     Obj(String name, int age, String place){
  46.         this.name = name;
  47.         this.age = age;
  48.         this.place = place;
  49.     }
  50.  
  51.     public String getName() {
  52.         return name;
  53.     }
  54.  
  55.     public void setName(String name) {
  56.         this.name = name;
  57.     }
  58.  
  59.     public int getAge() {
  60.         return age;
  61.     }
  62.  
  63.     public void setAge(int age) {
  64.         this.age = age;
  65.     }
  66.  
  67.     public String getPlace() {
  68.         return place;
  69.     }
  70.  
  71.     public void setPlace(String place) {
  72.         this.place = place;
  73.     }
  74.  
  75.  
  76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top