Video 49(ch10)

Yash
0

 



Program:-

class phone{
    public void showTime(){
        System.out.println("Time is 8 am");
    }
    public void on(){
        System.out.println("Starting the phone...");
    }
}
class Smartphone extends phone{
    public void music(){
        System.out.println("Playing music...");
    }
    public void on(){
        System.out.println("Starting the smartphone...");
    }
}

public class DynamicMethodDispatchV48 {
    public static void main(String[] args) {
        phone obj = new Smartphone();//Yes it is Allowed.
        //Smartphone obj2 = new phone(); // it is not Allowed.

        obj.showTime();
        obj.on();//print the "starting the smartphone" not "starting the phone".
        
        //obj.music(); not Allowed.
    }
}

Post a Comment

0 Comments
Post a Comment (0)
To Top