import com.fxmx.simple.*;
// com.fxmx.simple 패키지에 있는 모든 것을 불러오기
public class CircleObjectTest {
public static void main(String[] args) {
// com.fxmx.simple.Circle c1 = new com.fxmx.simple.Circle();
Circle c1 = new Circle();
com.wxfx.smart.Circle c2 = new com.wxfx.smart.Circle();
}
}
import com.fxmx.simple.*;
import com.wxfx.smart.*;
public class CircleObjectTest {
public static void main(String[] args) {
com.fxmx.simple.Circle c1 = new com.fxmx.simple.Circle();
com.wxfx.smart.Circle c2 = new com.wxfx.smart.Circle();
// Circle c1 = new Circle();
// Circle c2 = new Circle();
}
}
class Song2 {
String title;
String artist;
Song2(){
System.out.println("Default Constructor");
}
Song2(String title, String artist){
this(); // 생성자 함수 실행, 아랫줄에서 실행할 수 없다.
this.title = title;
this.artist = artist;
show(); // 코딩 상에서는 this를 생략할 수도 있다.
}
void show() {
System.out.println("Title : " + title + ", Artist : " + artist);
}
}
public class Hello {
public static void main(String[] args) {
Song2 song = new Song2("Dancing Queen", "ABBA");
System.out.println(song);
}
[Console]
Default Constructor // this() 실행
Title : Dancing Queen, Artist : ABBA // this.show() 실행
class TV {
int size;
String color;
public TV(int size, String color) {
this.size = size;
this.color = color;
}
public int getSize() {
return size;
}
public String getColor() {
return color;
}
public void show() {
System.out.println(getSize() + "인치, " + getColor() + "색입니다");
// System.out.println(this.size + "인치, " + this.color + "색입니다");
}
public void compareSize(TV tv) {
if(this.size > tv.getSize()) {
System.out.println("내가 더 크다.");
} else if(this.size == tv.getSize()) {
System.out.println("크기가 같다.");
} else {
System.out.println("내가 더 작다.");
}
}
}
public class Hello {
public static void main(String[] args) {
TV tv = new TV(10, "blue");
// System.out.println(tv.getSize() + "인치 입니다");
// System.out.println(tv.getColor() + "색입니다");
tv.show();
TV tv2 = new TV(20, "blue");
tv.compareSize(tv2); // 10인치는 20인치보다 작다
tv2.compareSize(tv); // 20인치는 10인치보다 크다
}
}