Question 1
Consider the Java code given below that prints the price of laptops. From among the options, identify the appropriate function header for the function printPrice that takes as input a list of laptops and prints their prices.
import java.util.*;class Laptop { private double price; public Laptop(double p) { price = p; } public double getPrice() { return price; }}class Dell extends Laptop { public Dell(double p) { super(p); }}class HP extends Laptop { public HP(double p) { super(p); }}
public class Test { // FUNCTION HEADER for function printPrice { for (int i = 0; i < lst.size(); i++) { System.out.println(lst.get(i).getPrice()); } }
public static void main(String[] args) { List<Dell> d = new ArrayList<Dell>(); d.add(new Dell(1000.00)); d.add(new Dell(1200.00));
List<HP> h = new ArrayList<HP>(); h.add(new HP(900.00)); h.add(new HP(1100.00));
printPrice(d); printPrice(h); }
}Choose the correct option.
