Time t =newTime();t.hour=12;t.minute=34;t.second=56;
Add constructor : To initialize instance(iv group) easily.
Time t =newTime(12,34,56);
classCar {String color;String gearType;int door;Car() {}//default constructorCar(String c,String g, ind d) {//iv group color = c; gearType = g; door = d; }}//1.declare reference type variable//2.create object using operator new//3.initialize with calling constructorCar c =newCar("white","auto",4);
when there is no constructor, compiler adds automatically.
classData_1 {//there is no constructor so compiler adds automatically.int value;//Data_1(){}}classData_2 {//there is one constructor.int value;//MUST include default constructor manuallyData_2() {}Data_2(int x) { value = x; }}classEx6_11 {publicstaticvoidmain(String[] args) {Data_1 d1 =newData_1();//call constructor;Data_2 d2 =newData_2();//call default constructor=>error.cannot resolve symbol : issue with name//must add default constructor in Data_2! }}
main classand other method classcan be separated like above?