IT/development

[java] extends (feat. simple)

์–ดํฅ๊ผฌ๋น„ 2024. 10. 23.

๋ชฉ์ฐจ

    ๋ถ€๋ชจ ํด๋ž˜์Šค

    package extends1.ex2;
    
    public class Parent {
    
        public void income() {
            System.out.println("์›”์„ธ๋ฅผ 10,000,000์› ๋ฐ›์Šต๋‹ˆ๋‹ค.");
        }
    }

    ์ž์‹ ํด๋ž˜์Šค

    package extends1.ex2;
    
    public class Child1 extends Parent {
    
        public void play() {
            System.out.println("๋†€์ž~~~~~~");
        }
    }

    Main

    package extends1.ex2;
    
    public class ChildMain {
    
        public static void main(String[] args) {
            Child1 child1 = new Child1();
            child1.play();
            child1.income();
            System.out.println("์ฐธ์œผ๋กœ ์ข‹๊ฒ ๊ตฌ๋‚˜");
        }
    }

    ๋ถ€๋ชจ์˜ ๊ฑด๋ฌผ์„ ๋ฌผ๋ ค ๋ฐ›์•„ ๋†€์•„๋„ ์ž„๋Œ€์†Œ๋“์œผ๋กœ ์ž˜ ๋จน๊ณ  ์ž˜ ์‚ฌ๋Š” ๊ฑธ ํ‘œํ˜„

    ๋ถ€๋ชจ์˜ ์ž„๋Œ€์ˆ˜์ž…์„ ์ƒ์†

    ๋Œ“๊ธ€