본문 바로가기
비트 장기/JAVA

7/17 복습(생성자 오버로딩)

by woohyun22 2018. 7. 18.
package practice1;
class Tiger{
int a,b,c;
Tiger(){
System.out.println("call");
}
Tiger(int x){
int a;
a=x;
//this.a;
}
Tiger(int x,int y){
this.a =x;
this.b = y;
}
Tiger(int x,int y,int z){
a=x;
b=y;
c=z;
}
void show(){
System.out.println(a+ " " + b+" "+c);
}
}
public class practice1 {
public static void main(String[] args) {
String n1 = new String("");
String n2 = new String();
Tiger t1 = new Tiger();
t1.show();
Tiger t2 = new Tiger(10);
t2.show();
Tiger t3 = new Tiger(10,20);
t3.show();
Tiger t4 = new Tiger(10,20,30);
t4.show();
}
}




package practice1;
class Tiger{
int a,b,c;
Tiger(){
System.out.println("call");
}
void func01(){
System.out.println("인수전달없는함수");
}
void func01(int x){
System.out.println("인수전달한개있는 함수");
}
void func01(int x,int y){
System.out.println("인수전달두개있는함수");
}
/*void func01(int y){//인수가 한개라 인수가 달라도 안된다
//받아들여지는 인수가 같다.
System.out.println("인수전달없는함수");
}*/
}
public class practice1 {
public static void main(String[] args) {
Tiger t1 = new Tiger();
t1.func01(3,5);
t1.func01();
t1.func01(3);
}
}

package practice1;
class Tiger{
int a,b,c;
Tiger(){
a=10;
b=20;
c=30;
System.out.println("call");
}
Tiger(int x){
a=x;
b=20;
c=30;
}
Tiger(int x ,int y){
a=x;
b=y;
c=30;
}
Tiger(int x,int y,int z){
a=x;
b=y;
c=z;
}
void output() {
System.out.println(a+" "+b+" "+c);
}
}
public class practice1 {
public static void main(String[] args) {
Tiger t1 = new Tiger();
Tiger t2 = new Tiger(1);
Tiger t3 = new Tiger(1,3);
Tiger t4 = new Tiger(1,3,4);
t1.output();
t2.output();
t3.output();
t4.output();
}
}


728x90

'비트 장기 > JAVA' 카테고리의 다른 글

7/18 복습  (0) 2018.07.19
7/18 배움(함수,overloading, 생성자 class, chaining, final, static)  (0) 2018.07.18
7/17 배움(class, 생성자)  (0) 2018.07.17
7/16 복습  (0) 2018.07.17
7/16 수업(class 복습, 예제)  (0) 2018.07.16

댓글