Constructor & Default Constructor

NOAH·2021년 2월 3일
0
post-thumbnail


/*
Constructor =>
what? Method
why? to reset instance variable

"reset" means renew iv

rule?
 - Constructor's Name should be equals to Class's
 - NO return values without 'void'
 - All class has more than one constructor
 -

Defualt Constructor

- constructor without parameter. But in the case
 of  class has no constructor,Compiler Automatically
 add constructor to class

 */


class Data_1 {
    int value;

}

class Data_2 {
    int value;

    Data_2(int x){
        value = x ;
    }

}


public class Ex6_11 {
    public static void main(String[] args){
        Data_1 d1 = new Data_1();
        Data_2 d2 = new Data_2(34);
    }
}

0개의 댓글