0

Help me to find a mistake in the bellow code in description

public class vehicle { private int number; private String name; private boolean offensive; vehicle (int nu,String n,boolean o ){ nu=number; n = name; o=offensive;} static void output(){ System.out.println(number+name+offensive); }} class executor{ public static void main(String[] args) { vehicle.v1=new vehicle(1213,"moto",true); vehicle v2=new vehicle (1312,"coro",false); output.v1(); output.v2(); } }

30th Aug 2020, 11:05 AM
Munaziri
2 ответов
+ 4
Wrong assignments => nu=number it should be number = nu; //destination <= source. And vehicle v1 = new vehicle(1312,"coro",false); //👆include space not dot And v1.output(); // not output.v1(); output method v1 is object. So object.method() [ But output is a static method hence you can access it by class name only.. So it shloud be vehicle.output().. But for correct result remove static, make public void output() {..} Revise again your learning will help you much..
30th Aug 2020, 11:28 AM
Jayakrishna 🇮🇳
+ 1
(1) at vehicle constructor you didn't assign your members but the parameters you passed in. (2) output() shouldn't be static as the output depend on each objects. (3) typo vehicle.v1 at main() (4) output.v1() -> v1.output() and so v2.
30th Aug 2020, 11:31 AM
你知道規則,我也是
你知道規則,我也是 - avatar