Concept explainers
// Superclass
public class Vehicle
{
public abstract double getMilesPerGallon( );
(Other methods …)
}
// Subclass
public class Car extends Vehicle
{
private int mpg;
public int getMilesPerGallon();
{
return mpg;
}
(Other methods…)
}
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Java How To Program (Early Objects)
C++ How to Program (10th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- What is the output of the following code? Convert the abstract class into an interface and modify the codes in all classes that will maintain the same output. (Rewrite the code)arrow_forwardpublic class A { public void funl () { System.out.println ("Al"); } public class B extends A { @Override public void funl () { super.fun1 () ; System.out.println ("B1"); public void fun2 () { System.out.println ("B2"); public class C extends B { @Override public void funl () { System.out.println ("C1");arrow_forwardWhat is outpout? public class Vehicle { public void drive(){ System.out.println("Driving vehicle"); } public class Plane extends Vehicle { @Override public void drive(){ System.out.println("Flying plane"); } public static void main(String args[]) { Vehicle myVehicle myVehicle.drive(); } } = new Plane(); syntax error Driving vehicle Flying plane Flying plane O Driving vehiclearrow_forward
- public class Car { private int modelYear; // TODO: Declare purchasePrice field (int) private int currentValue; public void setModelYear(int userYear){ modelYear = userYear; } public int getModelYear() { return modelYear; } // TODO: Define setPurchasePrice() method // TODO: Define getPurchasePrice() method public void calcCurrentValue(int currentYear) { double depreciationRate = 0.15; int carAge = currentYear - modelYear; // Car depreciation formula currentValue = (int) Math.round(purchasePrice * Math.pow((1 - depreciationRate), carAge)); } // TODO: Define printInfo() method to output modelYear, purchasePrice, and currentValue } import java.util.Scanner;import java.lang.Math; public class CarValue { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Car myCar = new Car(); int userYear = scnr.nextInt(); int userPrice = scnr.nextInt(); int…arrow_forwardJAVAarrow_forwardFinish the constructor for the KickBall class. public class Ball { public double diameter; public Ball(double diam) { diameter = diam; public class KickBall extends Ball private Color ballColor; public KickBall(double diam, Color ballColor) {arrow_forward
- public class Father { public String name; public int age; // customer name Father(){ name=”Hassan”; age=50;} public void display(){ System.out.println(“Name:”+name); System.out.println(“Age:”+age); } } 1. Based on Figure 3, create a class named Child that inherits the Father class. Declare an instance name location (String) for class Child. 2. Define a constructor in class Child and give an appropriate initial values for the instance (name, age, location). 3. Define a method display () in class Child, execute the display ( ) method in superclass using the keyword super. Method display ( ) in class Child should print the information of name, age and location 4. Create other class named Main for the main method and create 2 objects for the 2 classes (Father and Child). Then execute the display ( ) method for Father and Child. Example of the output as in Figure 4: Father's info: Name: Josh Age: 50 Child's info: Name: Christy Age: 20 Location:…arrow_forwardFind the Error. interface DAO{ public double getMax();public abstract double getAverage();} abstract class Human{ public abstract void study(); public void showValue(Number i){ System.out.println(i); }} class B extends Human implements DAO{ public void study() { System.out.println("Study OOP");}public double getMax() { return 30;}public double getAverage() { return 14.5;} @Overridepublic void getAccess() { System.out.println("233");}} public class AbstractionAndInterface {public static void main(String[] args) {Human h = new B();double res = h.getMax();System.out.println(res);B b = new B();System.out.println(b.getAverage());b.getAccess();}} public interface DAO2 {public void getAccess(); public abstract void printOutput();}arrow_forwardCreate a subclass named Square from the superclass Geometricobject. Create an instance variable named width with initial value 0. Create a no-arg constructor. Create the another constructor, which has one parameter named wid. ASsign the wid to the instance variable named width. Create the getWidth() method, the setWidth() method. Override the getArea() method. Override the getPerimeter() method. Create a test class named Test to create an instance with wid= 6 from Square class. Call the getArea() and getPermeter() methods to print out the area and perimeter of the square with width=6.arrow_forward
- Question 13 What is outpout? public class Vehicle { public void drive(){ System.out.println("Driving vehicle"); } } public class Plane extends Vehicle { @Override public void drive(){ System.out.println("Flying plane"); } public static void main(String args[]) { Vehicle myVehicle= = new Plane(); myVehicle.drive(); } Driving vehicle syntax error Flying plane Driving vehicle Flying plane }arrow_forwardpublic interface Joy ( public void happySign(); } public class Man implements Joy { public Man () { } public void happySign () { System.out.println("smiles"); } public void sadSign () { } red phot System.out.println("frowns"); a) Joy obj1 = new Man(); obj1.sadSign(); public class Dog implements Joy { public Dog () () public void happySign () { } System.out.println("wags tail"); public class GuardDog extends Dog { public GuardDog () { } public void happySign () { System.out.println("barks"); } We public void angrySign () { } System.out.println("growls"); If the following lines of code appeared in the main method of a driver program, would the program compile and run? (yes or no?) If no, write 1-2 sentences to explain why not. If yes, indicate what the output would be. nafn,arrow_forwardCode: interface Bicycle{ //interface for bicycle void changeGear(int val); //abstract methods void changeSpeed(int inc); void applyBrakes(int dec); void ringBell(int count); } class NewCycle implements Bicycle{ //class for a new cycle int speed=0; //stores the speed value int gear=0; //stores the gear value @Override public void changeGear(int val) { //method to change the gear gear=val; } @Override public void changeSpeed(int inc) { //method to change the speed speed=speed+inc; } @Override public void applyBrakes(int dec) { //method to apply brakes speed=speed-dec; } @Override public void ringBell(int count) { //method to ring the bell for(int i=0;i<count;i++){ System.out.print("Clang!!"+" "); } System.out.println(""); } public void printState(){ //method to print the states System.out.println("Ring bell, Speed, Gear,…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT