0% found this document useful (0 votes)
8 views2 pages

Kalpesh 8

The document contains code for two Java programs: 1) A method overloading example showing a class with two methods named "operation" that take in different parameters (int vs double) and return different types, and are called to demonstrate overloading. 2) A method overriding example with a parent "solar_system" class and child "planet" class, where the child class overrides the parent's method to output a different message.

Uploaded by

KALPESH BORSE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Kalpesh 8

The document contains code for two Java programs: 1) A method overloading example showing a class with two methods named "operation" that take in different parameters (int vs double) and return different types, and are called to demonstrate overloading. 2) A method overriding example with a parent "solar_system" class and child "planet" class, where the child class overrides the parent's method to output a different message.

Uploaded by

KALPESH BORSE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

JAVA PRACTICAL 2106066

Program 1:- Program for implementing method overloading:-

public class overload { //2106066

public static int operation(int a,int b)


{
return a+b;
}

public static double operation(double a,double b)


{
return a-b;
}

public static void main(String[] args)


{
System.out.println("Sum of 2 no.s "+operation(20,12));
System.out.println("Subtrarction of 2 no.s "+operation(30.12,12.22));

}
}

OUTPUT:-

1
JAVA PRACTICAL 2106066

Program 2 :- Program for implementing method overriding:-

class solar_system{ //2106066


{
System.out.println("Earth Revolves Around Sun");
}
}

class planet extends solar_system{


void earth()
{
System.out.println("Hello...Myself Earth");
}
}

public class override {

public static void main(String[] args)


{
planet obj=new planet();

obj.earth();

}
}

OUTPUT:-

You might also like