[JDQ3] 자바JAVA_모듈과 패키지Java/Daily Quiz2021. 9. 11. 18:00
목차
⚠️글 하단에 정답이 있습니다.
Q1.
Color 클래스를 만들고 해당 클래스가 Design 패키지에 소속되도록 키워드를 이용해 선언하는 코드를 작성하세요. (클래스 내부는 채우지 않아도 됨)
//Color 클래스를 Design 패키지에 저장하는 코드 작성
public class Color {
.....
}
Q2.
Shape 클래스를 만들고 해당 클래스에서 Color 클래스의 경로명을 알리세요.
//Shape 클래스를 Graphic 패키지에 저장하는 코드 작성
//Color 클래스의 경로명을 알리세요.
public class Shape {
public void method() {
Color c = new Color();
}
.....
}
Q3.
객체를 문자열로 변환하는 메소드는 무엇인가요? 그 메소드를 이용해서 Point 클래스를 만들고 다음의 실행 결과가 되도록 다음 코드를 채우세요.
class Point {
private int x,y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
//메소드를 작성하세요
}
public class ToStringEx {
public static void main(String[] args) {
// TODO Auto-generated method stub
//코드를 채우세요
}
}
//실행 결과
Point (2,3)입니다.
Q4.
다음 코드의 실행 결과를 적으세요.
public class EqualsEx {
public static void main(String[] args) {
// TODO Auto-generated method stub
String a = new String("apple");
String b = new String("banana");
String c = new String("banana");
String d = b;
if (b==c)
System.out.println("b==c");
if(b==d)
System.out.println("b==d");
if(a.equals(b))
System.out.println("a equals b");
if(b.equals(c))
System.out.println("b equals c");
}
}
정답
A1.
package Design;
public class Color {
.....
}
A2.
package Graphic;
import Design.Color;
public class Shape {
public void method() {
Color c = new Color();
}
.....
}
A3.
class Point {
private int x,y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public String toString() {
return "Point("+x+", "+y+")"+"입니다.";
}
}
public class ToStringEx {
public static void main(String[] args) {
// TODO Auto-generated method stub
Point p = new Point1(2,3);
System.out.println(p.toString());
}
}
A4.
b==d
b equals c
728x90
반응형
LIST
'Java > Daily Quiz' 카테고리의 다른 글
[JDQ4] 자바JAVA_모듈과 패키지(2) (0) | 2021.09.12 |
---|---|
[JDQ2] 자바JAVA_상속(2) (0) | 2021.09.05 |
[JDQ1] 자바JAVA_상속 (0) | 2021.09.04 |
@kdj :: Childev'note
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!