자바 기초

상속

coding1842 2024. 1. 27. 16:05
package com.study.javastudy.study;

public class Car1 {
    public void run() {
        System.out.println("달리다.");
    }
}

package com.study.javastudy.study;

public class Bus extends Car1{
    public void ppangppang() {
        System.out.println("빵빵");
    }
}

package com.study.javastudy.study;

public class BusExam{
    public static void main(String[] args) {
        Bus bus = new Bus();
        bus.run(); // 달리다
        bus.ppangppang(); // 빵빵

        Car1 car = new Car1();
        car.run();

//        car.ppangppang(); // 부모클래스는 자식이 가지고 있는 것을 사용 할 수 없다
    }
}