开发者

Setting a Variable in another class results in an error

开发者 https://www.devze.com 2023-01-23 18:26 出处:网络
What I am trying to do is set a value in a variable contained within another class. this is how I am currently trying to achieve it.

What I am trying to do is set a value in a variable contained within another class.

this is how I am currently trying to achieve it.

BookingUI Class

private void setCarRegNo() 
{
   aBooking.setCarRegNo();
}

Booking class

public void setCarRegNo(String regNo)
{
    carRegNo = regNo;
}

Yet I keep getti开发者_JAVA百科ng an error saying 'setCarRegNo (java.lang.String) in booking cannot be applied to ()

What is it I am doing wrong? Many thanks


You need to pass a String into the setCarRegNo(String ) of Booking class. The method signature declares that it requires a String argument, and your compiler will complain if you dont supply one.


You have to pass a string into the setCarRegNo() function. Like this: setCarRegNo("Some string");


In your Booking Class, setCarRegNo takes a single parameter of type String.

When you call it from BookingUI, you are not passing in any parameters.

You need to change BookingUI to something like:

private void setCarRegNo() 
{
   aBooking.setCarRegNo("CarRegNo");
}


you need to pass a string to your setter. change

 aBooking.setCarRegNo();

to

  aBooking.setCarRegNo("the registration number');

as a note, you should fully spell out the words of the variables.

0

精彩评论

暂无评论...
验证码 换一张
取 消