wasup
java 생성자 정의2 본문
반응형
package testPackage;
public class Member2 {
String name;
String tel;
String address;
Member2(){
name = "no name";
tel = "no tel";
address = "no address";
}
Member2(String _name){
name = _name;
tel = "no tel";
address = "no address";
}
Member2(String _name, String _tel, String _address){
name = _name;
tel = _tel;
address = _address;
}
void print() {
System.out.println("name : "+name);
System.out.println("tel : "+tel);
System.out.println("address : "+address);
}
}
package testPackage;
public class Member2Main {
public static void main(String[] args) {
Member2 m1 = new Member2();
m1.print();
Member2 m2 = new Member2("아이유");
m2.print();
Member2 m3 = new Member2("김말숙", "010-1111-8888", "대한민국");
m3.print();
}
}
//출력결과
name : no name
tel : no tel
address : no address
name : 아이유
tel : no tel
address : no address
name : 김말숙
tel : 010-1111-8888
address : 대한민국
반응형
'IT > Java' 카테고리의 다른 글
java) 자바 기초 복습2 (0) | 2021.03.29 |
---|---|
java) 자바 기초 복습 (0) | 2021.03.22 |
java 생성자 정의 (0) | 2020.11.23 |
java Method Overloading(오버로딩) (0) | 2020.11.22 |
java static memory(정적메모리)2 (0) | 2020.11.21 |
Comments