0% found this document useful (0 votes)
7 views

EXP6Java

java

Uploaded by

randivenivedi
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)
7 views

EXP6Java

java

Uploaded by

randivenivedi
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/ 3

EXP :- 6

A) Write a program in JAVA to demonstrate the method overloading

Name :- Nivedi Kiran Randive

Roll no:- 57

CODE:-

class OverloadDemo {

void test() {

System.out.println("No parameters");

void test(int a) {

System.out.println("a: " + a);

void test(int a, int b) {

System.out.println("a and b: " + a + " " + b);

double test(double a) {

System.out.println("double a: " + a);

return a * a;

public class Overload {

public static void main(String args[]) {

OverloadDemo ob = new OverloadDemo();

double result;

ob.test();

ob.test(10);

ob.test(10, 20);

result = ob.test(123.25);

System.out.println("Result of ob.test(123.25): " + result);

}
}

OUTPUT:-

No parameters

a: 10

a and b: 10 20

double a: 123.25

Result of ob.test(123.25): 15190.5625

B) Write a program in JAVA to demonstrate the constructor overloading

CODE:-

class Box {

double width, height, depth;

Box(double w, double h, double d) {

width = w;

height = h;

depth = d;

Box() {

width = height = depth = 0;

Box(double len) {

width = height = depth = len;

double volume() {

return width * height * depth;

public class Test {

public static void main(String args[]) {


Box mybox1 = new Box(10, 20, 15);

Box mybox2 = new Box();

Box mycube = new Box(7);

double vol;

vol = mybox1.volume();

System.out.println("Volume of mybox1 is " + vol);

vol = mybox2.volume();

System.out.println("Volume of mybox2 is " + vol);

vol = mycube.volume();

System.out.println("Volume of mycube is " + vol);

OUTPUT:-

Volume of mybox1 is 3000.0

Volume of mybox2 is 0.0

Volume of mycube is 343.0

You might also like