Monday, July 26, 2021

simple program using Dynamic Method Dispatch in Java (Java) (212)

package com.company;
class super1
{
public void sp()
{
System.out.println("this is a super phone");
}
public void on()
{
System.out.println("super phone starting...");
}
}
class sub1 extends super1
{
public void sbp()
{
System.out.println("this is a super phone");
}
public void on()
{
System.out.println("sub phone starting...");
}
}
public class program49 {
public static void main(String[] args) {
super1 obj=new sub1();
obj.sp();
obj.on(); //run the on() function of sub class
}
}

No comments:

Post a Comment