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
Instructor
Ashish Thakur Replied on 23/02/2021
public void refuel(int amount String time) {
should be
int amount, String time
Thanks sir my bad ..