๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

Java107

[Java] ์ •๋ณด ์€๋‹‰ โ–ถ ์ •๋ณด ์€๋‹‰ public (๋ชจ๋“  ๊ณณ์—์„œ ์ž์œ ๋กญ๊ฒŒ ์ ‘๊ทผ ๊ฐ€๋Šฅ) protected (์ƒ์† ๊ด€๊ณ„์— ์žˆ๋Š” ๊ณณ์€ ์ ‘๊ทผ ๊ฐ€๋Šฅ) → ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ณณ๋„ ์žˆ์Œ packaged (๊ฐ™์€ ํŒจํ‚ค์ง€ ์•ˆ์—์„œ ์ ‘๊ทผ ๊ฐ€๋Šฅ) private (๋‹ค๋ฅธ ํด๋ž˜์Šค์—์„  ๋ณผ ์ˆ˜ ์—†์Œ) → ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ณณ๋„ ์žˆ์Œ ๊ทธ๋Ÿฌ๋ฉด private์œผ๋กœ ์„ ์–ธํ•œ ๋ณ€์ˆ˜๋ฅผ ์™ธ๋ถ€์—์„œ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ• ๊นŒ? โ€‹ -๊ทธ๋Ÿฌ๊ธฐ์œ„ํ•ด์„  ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ํด๋ž˜์Šค์— public get( ), set( ) ๋ฉ”์„œ๋“œ๊ฐ€ ์ž…๋ ฅ๋˜์–ด์žˆ์–ด์•ผํ•จ. 2021. 2. 18.
[Java] ์ฐธ์กฐ ์ž๋ฃŒํ˜• โ–ถ ์ฐธ์กฐ ์ž๋ฃŒํ˜• -์ž๋ฃŒํ˜•์—๋Š” ํฌ๊ธฐ๊ฐ€ ์ •ํ•ด์ง„ ๊ธฐ๋ณธ ์ž๋ฃŒํ˜•(int, char, float, double ๋“ฑ)์œผ๋กœ ์„ ์–ธํ•˜๋Š” ๋ณ€์ˆ˜๊ฐ€ ์žˆ๊ณ , ํด๋ž˜์Šค ์ž๋ฃŒํ˜•์œผ๋กœ ์„ ์–ธํ•˜๋Š” ์ฐธ์กฐ ์ž๋ฃŒํ˜• ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋‹ค. ex) String package reference; public class Student1 { int studentID; String studentName; int koreaScore; int mathScore; } -String์ด ์ฐธ์กฐ ์ž๋ฃŒํ˜• โ€‹ 2021. 2. 18.
[Java] ์ƒ์„ฑ์ž ์˜ค๋ฒ„๋กœ๋“œ package constructor; public class Person { String name; float height; float weight; public Person() { // ๋””ํดํŠธ ์ƒ์„ฑ์ž } public Person(String name) { // ์ด๋ฆ„์„ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ž…๋ ฅ๋ฐ›๋Š” ์ƒ์„ฑ์ž name = name; } public Person(String name, float pheight, float weight) { // ์ด๋ฆ„, ํ‚ค, ๋ชธ๋ฌด๊ฒŒ๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ž…๋ ฅ๋ฐ›๋Š” ์ƒ์„ฑ์ž name = name; height = height; weight = weight; } } -ํด๋ž˜์Šค์— ์ƒ์„ฑ์ž๊ฐ€ ๋‘ ๊ฐœ ์ด์ƒ ์ œ๊ณต๋˜๋Š” ๊ฒฝ์šฐ๋ฅผ ์ƒ์„ฑ์ž ์˜ค๋ฒ„๋กœ๋“œ๋ผ๊ณ  ํ•œ๋‹ค. 2021. 2. 18.
[Java] ์ƒ์„ฑ์ž โ–ถ ์ƒ์„ฑ์ž package constructor; public class Person { String name; float height; float weight; } package constructor; public class PersonTest { public static void main(String[] args) { Person personLee = new Person(); // ์ƒ์„ฑ์ž } } -์ƒ์„ฑ์ž์˜ ์—ญํ• ์€ ์ฃผ๋กœ ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜์˜ ์ดˆ๊ธฐํ™”๋‹ค. โ–ถ ๋””ํดํŠธ ์ƒ์„ฑ์ž package constructor; public class Person { String name; float height; float weight; public Person() { // ์ž๋ฐ” ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ์ž๋™์œผ๋กœ ์ œ๊ณตํ•˜๋Š” ๋””ํดํŠธ ์ƒ์„ฑ์ž } } .. 2021. 2. 18.
[Java] ํด๋ž˜์Šค+์ธ์Šคํ„ด์Šค ๋งŒ๋“ค๊ธฐ ์‹ค์Šต ์ฑ…์œผ๋กœ ๋ฐฐ์šธ๋• ์ดํ•ด๊ฐ€ ์ž˜ ์•ˆ๊ฐ”๋Š”๋ฐ ์‹ค์Šต ํ•œ๋ฐฉ์œผ๋กœ ์ดํ•ด ์™„๋ฃŒ ์ˆ˜์—… 2021. 2. 18.
[Java] ์ฐธ์กฐ ๋ณ€์ˆ˜์™€ ์ฐธ์กฐ ๊ฐ’ โ–ถ ์ฐธ์กฐ ๋ณ€์ˆ˜์™€ ์ฐธ์กฐ ๊ฐ’ package classpart; public class StudentTest2 { public static void main(String[] args) { Student student1 = new Student(); student1.studentName = "์•ˆ์—ฐ์ˆ˜"; Student student2 = new Student(); student2.studentName = "์•ˆ์Šน์—ฐ"; System.out.println(student1); // ์ฐธ์กฐ ๋ณ€์ˆ˜ ๊ฐ’ ์ถœ๋ ฅ System.out.println(student2); // ์ฐธ์กฐ ๋ณ€์ˆ˜ ๊ฐ’ ์ถœ๋ ฅ } } -ํž™ ๋ฉ”๋ชจ๋ฆฌ์— ์ƒ์„ฑ๋œ ์ธ์Šคํ„ด์Šค์˜ ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ๋Š” ์ฐธ์กฐ ๋ณ€์ˆ˜์— ์ €์žฅ๋œ๋‹ค. -ํ•ด์‹œ ์ฝ”๋“œ(hash code)๊ฐ’ : ์ž๋ฐ” ๊ฐ€์ƒ ๋จธ์‹ ์—์„œ ๊ฐ์ฒด๊ฐ€ ์ƒ.. 2021. 2. 18.
๋ฐ˜์‘ํ˜•