java - Eclipse error : cannot be resolved to a type -


so doing exercise simulates car instruments. there 3 classes in total : fuelgauge, odometer , carinstrumentsimulator (the 1 main method). 2 first ones each have constructor have defined. whenever type in main:

public static void main(string[] args) {      carinstrumentsimulator carinstrumentsimulator = new carinstrumentsimulator();      fuelgauge fuel = carinstrumentsimulator.new fuelgauge();     odometer odometer = carinstrumentsimulator.new odometer(0, fuel); 

i carinstrumentsimulator.fuelgauge cannot resolved type error in eclipse(and same odometer), got line of code correction detailed in website got exercise (https://www.leveluplunch.com/java/exercises/car-instrument-simulator/) new java , coding in general, wondering : 1) syntax mean:

    fuelgauge fuel = carinstrumentsimulator.new fuelgauge(); 

2) why there problem syntax?

thanks in advance ^^

i think that's typo in source. try instead:

fuelgauge fuel = new fuelgauge(); odometer odometer = new odometer(0, fuel); 

there no sensible answer question ...

what syntax mean : fuelgauge fuel = carinstrumentsimulator.new fuelgauge();

... because line in question gibberish ;)

valid method invocation on java object (such carinstrumentsimulator) require dot notation, method name , opening , closing brackets e.g. carinstrumentsimulator.dosomething() above code not have opening , closing brackets, uses word new not valid java method name (since reserved keyword) , new followed fuelgauge() makes whole thing uninterpretable.

more details on java method construction here.

if fuelgauge declared inside carinstrumentsimulator syntax valid:

new carinstrumentsimulator.fuelgauge();  

similarly, if carinstrumentsimulator exposed creator method fuelgauge syntax valid:

carinstrumentsimulator.newfuelgauge(); 

but syntax isn't valid in circumstances: carinstrumentsimulator.new fuelgauge();.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -