+ 1
Please help to solve one error keep comming
Whats wrong in this please help to solve public class Vehicle { private String speed; public String getSpeed(){ return speed; } public String setSpeed(String x){ this.speed=x; } } class program { public static void main(String[]args){ Vehicle duke=new Vehicle(); Vehicle fz=new Vehicle(); duke.setSpeed ("ten"); System .out.println (duke.getSpeed()); fz.setSpeed("five"); System.out.println (fz.getSpeed ());
2 odpowiedzi
+ 7
corrected code:
class Vehicle {
    private String speed;
    public String getSpeed(){
        return speed;
    }
    public String setSpeed(String x){
        this.speed=x;
        return "";
    }
}
public class Program
{
    public static void main(String[] args) {
        Vehicle duke=new Vehicle();
        Vehicle fz=new Vehicle();
        duke.setSpeed ("ten");
        System.out.println (duke.getSpeed());
        fz.setSpeed("five");
        System.out.println (fz.getSpeed ());
    }
}
you forgot the return statement in your setSpeed method, you could change it to void, that way you wouldn't have to return anything
other than that I formatted the code a bit, and made some small changes
+ 2
Why are you making duplicate questions? your previous thread had an answer already.
https://www.sololearn.com/Discuss/749010/?ref=app



