public class Box {
int height = 5; // Initializing variables of Box
int width = 10;
int depth = 5;
public void Change_Box_Value(int h, int w, int d) { // method of changeing height, width, and depth
this.height = h;
this.width = w;
this.depth = d;
}
public void Info_Box() { // method of Showing infos of Box
System.out.println("height of box : " + height + ", width of box: " + width + ", depth of box: " + depth);
}
public static void main(String[] args) {
Box shoeBox = new Box(); // Creating Constructors
Box cookieBox = new Box();
Box fruitBox = new Box();
System.out.print("shoeBox>> "); // Info of shoeBox
shoeBox.Info_Box();
System.out.print("cookieBox>> "); // Info of cookieBox
cookieBox.Info_Box();
System.out.print("fruitBox>> "); // Info of fruitBox
fruitBox.Info_Box();
fruitBox.Change_Box_Value(10, 10, 10); // changing value of fruitBox
System.out.println("Volume of fruitBox: " + fruitBox.height * fruitBox.width * fruitBox.depth); // Printing volume of fruitBox
}
}
위에는 제가 짠 코드이고..
물어볼거는 밑에 각 문항의 답인데 이게 맞는건지 좀 봐주세요
(1) 지역변수 > h, w, d
(2) 멤버변수 > height, width, depth
(3) 멤버메소드
void Change_Box_Value(int h, int w, d) {}, void Info_Box() {}
- dc official App
1번은 매개변수아님?
ㅇㅇ 그럼 내가 쓴게 맞지? - dc App
잠깐 그럼 this 인스턴스 변수도 지역변수로 해야하나? this.변수명 이런식으로? - dc App