Quantcast
Channel: User Federico klez Culloca - Stack Overflow
Viewing all articles
Browse latest Browse all 485

Answer by Federico klez Culloca for My method in Java return always true or false without what inside my if else

$
0
0

In your second constructor (the one you're actually using in your main method)

public Motorcycle(String name, int yearOfProduction, int price, int weight, String color, String engineType, boolean isReadyToDrive, int distance) {    // previous statements omitted    this.isReadyToDrive = destroyEngine();    this.distance = distance;}

The destroyEngine methods uses the instance variable distance to decide whether to return true or false. But, as currently written, the distance instance variable still has its default value of 0.

You have to give it a value before calling destroyEngine.

public Motorcycle(String name, int yearOfProduction, int price, int weight, String color, String engineType, boolean isReadyToDrive, int distance) {    // previous statements omitted    this.distance = distance;    this.isReadyToDrive = destroyEngine();}

Viewing all articles
Browse latest Browse all 485

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>