코딩배움일지/JAVA
Java 10일차 2(오브젝트)
karatejin
2022. 11. 23. 12:23
public class ObjectArray {
public static Object getObject(Object obj) {
return obj;
}
public static void main(String[] args) {
Object[]objects = new Object[7];
objects[0] = new Student(20220001, "박수현");
objects[1] = new Car("쏘나타","화이트");
objects[2] = new Student(20220002, "박수현");
objects[3] = new Car("k5","블랙");
objects[4] = new Student(20220003, "황석민");
objects[5] = "김준일";
objects[6] = 20221123;
for (int i = 0; i < objects.length; i++) {
System.out.println(objects[i]);
}
}
}
Student{code=20220001, name='박수현'}
Car{model='쏘나타', color='화이트'}
Student{code=20220002, name='박수현'}
Car{model='k5', color='블랙'}
Student{code=20220003, name='황석민'}
김준일
20221123
Process finished with exit code 0
objects[5] = "김준일";
objects[6] = 20221123;
System.out.println(objects[5].getClass());
System.out.println(objects[6].getClass());
class java.lang.String
class java.lang.Integer
objects[6] = 20221123.5;
2.02211235E7
class java.lang.Double