πŸ“˜ [ JAVA 클래슀 λ³€μˆ˜ & μΈμŠ€ν„΄μŠ€ λ³€μˆ˜ ]

rossiebiΒ·2022λ…„ 12μ›” 10일
0

πŸ’» JAVA κ°œλ°œμΌμ§€Β 

λͺ©λ‘ 보기
32/38
post-thumbnail

⭐ μ„ μ–Έ μœ„μΉ˜μ— λ”°λ₯Έ λ³€μˆ˜μ˜ μ’…λ₯˜

  1. ν΄λž˜μŠ€λ³€μˆ˜ (class variable)
  • 클래슀 μ˜μ—­μ— μ„ μ–Έ
  • μΈμŠ€ν„΄μŠ€ λ³€μˆ˜ μ•žμ— static을 뢙이면 됨
  • μΈμŠ€ν„΄μŠ€λ₯Ό μƒμ„±ν•˜μ§€ μ•Šκ³  μ–Έμ œλ“  μ‚¬μš© κ°€λŠ₯
  1. μΈμŠ€ν„΄μŠ€λ³€μˆ˜ (instance variable)
  • 클래슀 μ˜μ—­μ— μ„ μ–Έ
  • μΈμŠ€ν„΄μŠ€λ₯Ό μƒμ„±ν• λ•Œ λ§Œλ“€μ–΄μ§
  1. μ§€μ—­λ³€μˆ˜ (local variable)
  • 클래슀 μ˜μ—­ μ΄μ™Έμ˜ μ˜μ—­
  • μ§€μ—­λ³€μˆ˜κ°€ μ„ μ–Έλœ λΈ”λŸ­ λ‚΄μ—μ„œλ§Œ μ‚¬μš© κ°€λŠ₯
  • λΈ”λŸ­μ„ λ²—μ–΄λ‚˜λ©΄ μ†Œλ©Έ

πŸ’₯ 클래슀 λ³€μˆ˜μ™€ μΈμŠ€ν„΄μŠ€ λ³€μˆ˜

class Card{
		String kind; //무늬
        int number; //숫자  -> μΈμŠ€ν„΄μŠ€λ³€μˆ˜(κ°œλ³„μ†μ„±)
        
        static int width=100; // 폭
        static int height=100; // 높이 -> ν΄λž˜μŠ€λ³€μˆ˜(곡톡속성)
        
        
  • 각 μΉ΄λ“œ μΈμŠ€ν„΄μŠ€λŠ” μžμ‹ λ§Œμ˜ 무늬, 숫자λ₯Ό κ°€μ Έμ•Όν•΄ μΈμŠ€ν„΄μŠ€ λ³€μˆ˜λ‘œ μ„ μ–Έ
  • 각 μΉ΄λ“œμ˜ 폭, λ†’μ΄λŠ” λͺ¨λ“  μΈμŠ€ν„΄μŠ€κ°€ κ³΅ν†΅μ μœΌλ‘œ 같은 값을 κ°€μ Έμ•Όν•΄ 클래슀 λ³€μˆ˜λ‘œ μ„ μ–Έ
profile
λΉ„μ „κ³΅μž 개발자λ₯Ό κΏˆκΎΈλŠ” λ‘œμ§€

0개의 λŒ“κΈ€