#1 Language ๐/1-4 JAVA
[JAVA] ์ธ์คํด์ค ๋ฉค๋ฒ, ์ ์ ๋ฉค๋ฒ ์ฌ์ฉ
FillByCoding
2022. 11. 6. 16:34
// ํด๋์ค ์ ์ธ
package Day03;
public class Car {
// ์ธ์คํด์ค ๋ฉค๋ฒ
String company;
//์ ์ ๋ฉค๋ฒ
// ์ ์ ๋ฉค๋ฒ
// static ๋ฉค๋ฒ๋ heap ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฌ
// heap๋ฉ๋ชจ๋ฆฌ๋ ์ผ๋ฐ ๋ฉ๋ชจ๋ฆฌ๋ณด๋ค ์ฉ๋์ด ์ ๊ธฐ ๋๋ฌธ์
//๊ณผ๋ํ static ๋ฉค๋ฒ์ ์ฌ์ฉ์ ํ๋ก๊ทธ๋จ ๊ณผ๋ถํ๋ฅผ ์ผ๊ธฐ
static String color = "๋ ๋";
public Car() {
company = "ํ๋";
}
// ์ธ์คํด์ค ๋ฉค๋ฒ(๋ฉ์๋)
void companyInfo() {
company = "ํ๋";
System.out.println("์ ์กฐ์ฌ๋ : " + company);
}
// ์ ์ ๋ฉค๋ฒ(๋ฉ์๋)
static void colorInfo() {
System.out.println(color);
}
}
// ์ ์ธํ ์ธ์คํด์ค, ์ ์ ๋ฉค๋ฒ ์ฌ์ฉ
package Day03;
public class _01_static {
public static void main(String[] args) {
// TODO Auto-generated method stub
// ์ ์ ๋ฉค๋ฒ(์์ฑ) ์ฌ์ฉ
// ๊ฐ์ฒด ์์ฑ์์ด ์ฌ์ฉ ๊ฐ๋ฅ
String carColor = Car.color;
System.out.println(carColor);
System.out.println("------------------------------");
// ์ ์ ๋ฉ์๋ ์ฌ์ฉ
Car.colorInfo();
System.out.println("------------------------------");
// ์ธ์คํด์ค ๋ฉค๋ฒ ์ฌ์ฉ
Car car = new Car();
String carCompany = car.company;
System.out.println(carCompany);
System.out.println("------------------------------");
car.companyInfo();
System.out.println("------------------------------");
LIST