source file name:   InheritanceOverload.java

class A

{

int x;

public A(int a)

     {

     x=a;

     }

public void display()

{

System.out.println("class A");

}

}

class B extends A

{


int y;

public B(int a,int b)

     {

super(a);

      y=b;

     }

public void display()

{

int gcd=gcd();

int lcm=lcm(gcd);

System.out.println("GCD of " +x+ "&" +y+ " is: " +gcd);

System.out.println("LCM of " +x+ "&"+y+ "is: " +lcm);

}


int gcd()

{

int temp; 

int m,n;

m=y;

n=x;

int gcd=0;

while(n!=0)

       {

temp=m%n;

        m=n;

        n=temp;

       }

gcd=m;


return gcd;

}

int lcm(int g)

{

int lcm;

lcm=(x*y)/g;

return lcm;

}

}


class InheritanceOverload

{

public static void main(String as[])

{

B b=new B(60,8);

b.display();

}

}

output:


D:\JavaPrograms\InheritancePrgs>javac "InheritanceOverload.java"


D:\JavaPrograms\InheritancePrgs>java InheritanceOverload

GCD of 24&12 is: 12

LCM of 24&12is: 24


D:\JavaPrograms\InheritancePrgs>javac "InheritanceOverload.java"


D:\JavaPrograms\InheritancePrgs>java InheritanceOverload

GCD of 60&8 is: 4

LCM of 60&8is: 120