Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- ์ปจํธ๋กค๋ฌ
- ํ ์ด๋ธ
- Spring
- ์๋ฐ์คํฌ๋ฆฝํธ
- ๋ณ์
- ๋ฐฐ์ด
- select
- ์ฝํ
- Update
- ๋์
- order by
- post๋ฐฉ์
- Ajax
- ๋์ ํ ์ด๋ธ
- ๋์ปค
- JavaScript
- SQL
- DATE_FORMAT
- optionํ๊ทธ
- ์ธ๋ผ์ธ๋ทฐ
- ํ๋ก๊ทธ๋๋จธ์ค
- MySQL
- ๋ช ๋ น์ด
- like
- ํจ์
- JS
- ๋ฐฑํฑ
- ๋ฆฌ๋ ์ค
- JSP
- oracle
Archives
- Today
- Total
bom's happy life
์ถ์ํด๋์ค ์์ ๋ณธ๋ฌธ
์ฌ๋ฌ ํด๋์ค๊ฐ ๊ณตํต์ ์ผ๋ก ๊ฐ์ง๋ ํน์ฑ์ ์ถ์ ํด๋์ค๋ก ์ถ์ถํ๋ ๊ฒฝ์ฐ
์๋ฅผ ๋ค์ด, ๋๋ฌผ์ ๋ชจ๋ธ๋งํ๋ ํด๋์ค๋ค์ด ์๋ค๊ณ ๊ฐ์ .
๊ฐ ๋๋ฌผ์ ์๋ฆฌ๋ฅผ ๋ด๋ ๋ฉ์๋๋ฅผ ๊ฐ์ง ์ ์์ง๋ง,
๊ฐ ๋๋ฌผ๋ง๋ค ์๋ฆฌ๋ฅผ ๋ด๋ ๋ฐฉ์์ ๋ค๋ฅผ ๊ฒ.
์ด๋ฐ ๊ฒฝ์ฐ, ์ถ์ ํด๋์ค์ ์ถ์ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ๊ณตํต์ ์ธ ํน์ฑ์ ์ถ์ถํ ์ ์๋ค.
// ์ถ์ ํด๋์ค Animal ์ ์
abstract class Animal {
private String name;
// ์์ฑ์
public Animal(String name) {
this.name = name;
}
// ์ถ์ ๋ฉ์๋ - ๋๋ฌผ์ด ์๋ฆฌ๋ฅผ ๋ด๋ ๊ธฐ๋ฅ
public abstract void makeSound();
// ์ผ๋ฐ ๋ฉ์๋ - ๋๋ฌผ์ ์ด๋ฆ์ ๋ฐํ
public String getName() {
return name;
}
}
// Animal ํด๋์ค๋ฅผ ์์๋ฐ์ ๊ตฌ์ฒด์ ์ธ ๋๋ฌผ ํด๋์ค๋ฅผ ์ ์
class Dog extends Animal {
// ์์ฑ์
public Dog(String name) {
super(name);
}
// ์ถ์ ๋ฉ์๋ ๊ตฌํ
@Override
public void makeSound() {
System.out.println(getName() + "๊ฐ ๋ฉ๋ฉ ์ง์ต๋๋ค.");
}
}
class Cat extends Animal {
// ์์ฑ์
public Cat(String name) {
super(name);
}
// ์ถ์ ๋ฉ์๋ ๊ตฌํ
@Override
public void makeSound() {
System.out.println(getName() + "๊ฐ ์ผ์น ์๋ฆฌ๋ฅผ ๋
๋๋ค.");
}
}
public class Main {
public static void main(String[] args) {
Animal dog = new Dog("๋ฉ๋ฉ์ด");
dog.makeSound(); // ๋ฉ๋ฉ์ด๊ฐ ๋ฉ๋ฉ ์ง์ต๋๋ค.
Animal cat = new Cat("์ผ์น์ด");
cat.makeSound(); // ์ผ์น์ด๊ฐ ์ผ์น ์๋ฆฌ๋ฅผ ๋
๋๋ค.
}
}
'Deveolpment Study๐๏ธ > JAVA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ ํํฌ์๋ฐ_์๋ฐ๊ณต๋ถํ๋ ์ฌ์ดํธ (0) | 2023.05.17 |
---|---|
arrayList()์ add๋ฉ์๋ (0) | 2023.05.17 |
[JAVA] String.join( ) ๋ฉ์๋ (0) | 2023.04.28 |
[JAVA] ํฅ์๋ for๋ฌธ (0) | 2023.04.28 |
[JAVA] Character ํด๋์ค (0) | 2023.04.28 |