Getting errors on method overloading | Selenium Forum
K
Karan Vaidyanathan Atreya Posted on 22/02/2021

Hi,

I tried to write the exact code for method overloading.

But it keeps showing me the error as Duplicate method please rename.

Can you please help out.

Below is the code snippet-

package oopsa;

public class carkaran {

public int fuelcapacity;

public carkaran() {
System.out.println("car default constructor");
fuelcapacity=10;
System.out.println(fuelcapacity);
}

public carkaran(int fuelcapacity) {
fuelcapacity=100;
System.out.println("car overloaded constructor");
this.fuelcapacity=fuelcapacity;

}

public void start() {

}

public void stop() {

}

public void refuel() {
System.out.println("refuel");
}


public void refuel(int amount) {
System.out.println("refuel amount "+amount);
}

public void refuel(int amount String time) {
System.out.println("refuel amount "+amount+" at time " + time);
}

}

Thanks


A
Ashish Thakur Replied on 23/02/2021

public void refuel(int amount String time) {

should be

int amount, String time


K
Karan Vaidyanathan Atreya Replied on 23/02/2021

Thanks sir my bad ..


Related Posts