Question: will following code work? if it will then what is the output and if it will not then why will it not? public class Car{

will following code work? if it will then what is the output and if it will not then why will it not? public class Car{ String name, color; int topSpeed; Car(String name, String color, int topSpeed){ this.name = name; this.color = color; this.topSpeed = topSpeed; } public void drive(){ System.out.println("You are now driving."); } public boolean race(){ System.out.println("You are now racing."); return false; } } public class Audi extends Car{ boolean turbo = false; Audi(String name, String color, int topSpeed, boolean turbo){ super(name, color, topSpeed); this.turbo = turbo; } public boolean race(){ System.out.println("you are now racing."); turbo = true; return turbo; } } public class Main{ public static void main(String[] args){ Car myCar = new Audi("R-8", "Black", 190, true); boolean turbo = myCar.race(); System.out.println("turbo: " + turbo); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!