π μμ±μλ?
: κ°μ²΄κ° newμ°μ°μλ₯Ό ν΅ν΄ Heapλ©λͺ¨λ¦¬ μμμ ν λΉλ λ κ°μ²΄ μμμ λ§λ€μ΄μ§λ νλ μ΄κΈ°ν
: μμ±μλ μΌμ’ μ λ©μλλ‘ μ λ¬λ μ΄κΈ°κ°μ λ°μμ κ°μ²΄μ νλμ κΈ°λ‘
πΉ μμ±μ κ·μΉ
: μμ±μμ μ μΈμ λ©μλ μ μΈκ³Ό μ μ¬νλ λ°ν κ°μ΄ μμΌλ©°
: μμ±μλͺ μ ν΄λμ€λͺ κ³Ό λκ°μ΄ μ§μ ν΄μ£Όμ΄μΌν¨
π κΈ°λ³Έ μμ±μ
: μμ±νμ§ μμ κ²½μ°, ν΄λμ€ μ¬μ© μ JVMμ΄ μλμΌλ‘ κΈ°λ³Έ μμ±μ μμ±
π λ§€κ°λ³μ μμ±μ
: κ°μ²΄ μμ± μ μ λ¬ λ°μ κ°μΌλ‘ κ°μ²΄λ₯Ό μ΄κΈ°ν νκΈ° μν΄ μ¬μ©
: λ§€κ° λ³μ μμ±μ μμ± μ JVMμ΄ κΈ°λ³Έ μμ±μλ₯Ό μλμΌλ‘ μμ±ν΄μ£Όμ§ μμ
: μμμμ μ¬μ© μ λ°λμ κΈ°λ³Έ μμ±μλ₯Ό μμ±
: μ€λ²λ‘λ©μ μ΄μ©νμ¬ μμ±
π» μ€λ²λ‘λ©μ΄λ?
: ν ν΄λμ€ λ΄μ λμΌν μ΄λ¦μ λ©μλλ₯Ό μ¬λ¬κ° μμ±νλ κΈ°λ²
πΉ μ€λ²λ‘λ© μ‘°κ±΄
: κ°μ λ©μλ μ΄λ¦
: λ€λ₯Έ λ§€κ°λ³μμ κ°μ λλ λ€λ₯Έ λ§€κ°λ³μ νμ
package kh.oop1.day03.exam;
public class OverloadingExam {
//μ€λ²λ‘λ© μ‘°κ±΄
//1. λ©μλμ μ΄λ¦μ λμΌν΄μΌνλ€.
int intI;
String strS;
public void method() {
}
//2. λ§€κ°λ³μμ νμ
μ΄ λ¬λΌμΌνλ€.
public void method(int intI) {
}
public void method(String strS) {
}
//3. λ§€κ°λ³μμ κ°μκ° λ¬λΌμΌνλ€.
public void method(int intI, String strS) {
}
//4. [μ£Όμ] λ§€κ°λ³μμ μμΉκ° λ¬λΌλ λ€λ₯Έ λ©μλλΌκ³ μΈμ
public void method(String strS, int intI) {
}
}
π thisλ?
: λͺ¨λ μΈμ€ν΄μ€μ λ©μλμ μ¨κ²¨μ§ μ± μ‘΄μ¬νλ λ νΌλ°μ€λ‘, ν λΉλ κ°μ²΄λ₯Ό κ°λ¦¬ν¨λ€.
: ν¨μ μ€ν μ μ λ¬λλ κ°μ²΄μ μ£Όμλ₯Ό μλμΌλ‘ λ°μ
π this()λ?
: μμ±μ, κ°μ ν΄λμ€μ λ€λ₯Έ μμ±μλ₯Ό νΈμΆν λ μ¬μ©, λ°λμ 첫λ²μ§Έ μ€μ μ μΈν΄μΌνλ€.
package kh.oop1.day03.exam;
public class ThisConstructor {
private String bookName; //μ±
μ΄λ¦
private int bookprice; //μ±
κ°κ²©
private String bookpublisher; //μΆνμ¬
private int bookid; //μ±
μμ΄λ
public ThisConstructor() {
System.out.println("κΈ°λ³Έμμ±μμ
λλ€.");
}
public ThisConstructor(String bookpublisher) {
this.bookpublisher = bookpublisher;
System.out.println("λ§€κ°λ³μ νλ");
}
public ThisConstructor(String bookName, int bookprice, int bookid) {
this("khμ 보κ΅μ‘μ");
this.bookName = bookName;
this.bookprice = bookprice;
this.bookid = bookid;
}
//getter
public String getBookName() {
return bookName;
}
public int getBookprice() {
return bookprice;
}
public String getBookpublisher() {
return bookpublisher;
}
public int getBookId() {
return bookid;
}
}
package kh.oop1.day03.run;
import kh.oop1.day03.exam.BasicVariable;
import kh.oop1.day03.exam.BlockExam;
import kh.oop1.day03.exam.FieldExam;
import kh.oop1.day03.exam.ThisConstructor;
public class Run {
public static void main(String[] args) {
ThisConstructor ts = new ThisConstructor("κ°μ²΄", 1000, 1);
System.out.println("μ±
μ΄λ¦ : " + ts.getBookName()
+ "μ±
κ°κ²© : " +ts.getBookprice()
+ "μΆνμ¬ : " + ts.getBookpublisher()
+ "μ±
μμ΄λ : " +ts.getBookId());
}
}
/*
λ§€κ°λ³μ νλ
μ±
μ΄λ¦ : κ°μ²΄μ±
κ°κ²© : 1000μΆνμ¬ : khμ 보κ΅μ‘μμ±
μμ΄λ : 1
*/
'Dev > Java' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[κ°μ²΄(7)] κ°μ²΄ λ°°μ΄ (0) | 2022.05.10 |
---|---|
[κ°μ²΄(6)] λ©μλ(Method) (0) | 2022.05.10 |
[κ°μ²΄(4)] νλ(Field) (0) | 2022.05.10 |
[κ°μ²΄(3)] packageμ import (0) | 2022.05.10 |
[κ°μ²΄(2)] ν΄λμ€, μ μΈ, μ κ·Όμ νμ, μμ±μ, getter, setter (0) | 2022.05.10 |