Heap 2

Dec 21, 2023
Heap 2
 
๐Ÿ’ก
๋™์ ์œผ๋กœ ํ• ๋‹น๋œ ๋ฉ”๋ชจ๋ฆฌ ์˜์—ญ
 
๊ฐ์ฒด ์ƒ์„ฑ : ํด๋ž˜์Šค๋ช… + ๋ณ€์ˆ˜๋ช… = new ํด๋ž˜์Šค๋ช…() ;
ScopeEx01 sc = new ScopeEx01();
 
public class ScopeEx02 { int n1 = 1; static int n2 = 2; static void m1() { int n3 = 10; System.out.println("m1:" + n3); } void m2() { System.out.println("m2:" + n1); } public static void main(String[] args) { ScopeEx01 sc = new ScopeEx01(); System.out.println(sc.n1); sc.m2(); } }
notion image
์œ„์˜ ์ฝ”๋“œ์—์„œ ๋ณ€์ˆ˜๋Š” ์ด๋Ÿฐ ๊ณต๊ฐ„์— ํ• ๋‹น๋œ๋‹ค.
heap ์„ ์ด์šฉํ•˜๊ธฐ ์œ„ํ•ด๋Š” new ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
ScopeEx01 sc = new ScopeEx01();
 
 
์ด๋ ‡๊ฒŒ ๋™์  ํ• ๋‹น์ด ๋˜๋ฉด static ์ด ์—†๋Š” ๋ชจ๋“  ๋ณ€์ˆ˜๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
notion image
 
๐Ÿ’ก
๋ฉ”์ธ stack์— ํ• ๋‹น๋œ ๋ณ€์ˆ˜ sc๋Š” ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ์žˆ์ง€ ์•Š๊ณ  heap ์— ์žˆ๋Š” ๊ฐ’์˜ ์ฃผ์†Œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ๊ทธ๋ž˜์„œ ์ฐธ์กฐ๋ณ€์ˆ˜๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.
 
Share article

{CODE-RYU};