Do not judge strictly, a couple of days ago I decided to suddenly learn programming and downloaded a book for children on Java. I do this task: I create a class

public class Car { int distance=0; public void start() { System.out.println("Я поехал!"); } public void stop() { System.out.println("Я остановился!"); } public int drive(int howlong){ distance=howlong*60; System.out.println("Проехано уже " + distance + " м"); return distance; } } 

I create a class that will run.

 public class CarOwner { public static void main(String[] args) { Car myCar = new Car(); myCar.start(); myCar.drive(3); myCar.stop(); } } 

At startup, the console issues

I went!
Already 180 meters driven
I stopped!

Next, create a subclass

 public class BondCar extends Car { public int drive(int howlong){ return distance=howlong*180; } } 

Create class to manage subclass

 public class CarOwnerBond { public static void main(String[] args) { BondCar myBondCar = new BondCar(); myBondCar.start(); myBondCar.drive(3); myBondCar.stop(); } } 

At startup, the console issues

I went! I stopped!

Why doesn't override work?

  • and why calculate that something is not working for you? - DreamChild
  • one
    In general, the myBondCar.drive method does not output to the console, nor do you use the return value when you call it, so you don’t see the result. However, this does not mean that it is not there - the method was implemented quite successfully - DreamChild
  • 3
    @VladD I think this phrase explains a lot:> a couple of days ago I decided to suddenly learn programming - DreamChild
  • one
    Understood, thank you! What books would you recommend for me, knowing my phrases, which explain a lot? - LS15
  • one
    @ LS15 I don’t do java myself, so I won’t be able to recommend something to you, but your question on the books is quite frequent (just yesterday you asked it here), so google the forum (or even the Internet), most likely something find - literature on this language in bulk. Most likely, Horstman, Ekkel, Schildt (or whose books are most popular there) will advise you. However, there is a strong opinion about Shield that he sins with inaccuracies in his books - DreamChild

1 answer 1

There seems to be no console output in your BondCar.drive method.

  • four
    comments do not read @ immediately write the answer - VladD