1. What is the output of the following Java program?interface Food { public void printFlavor();}
class Pepper extends Food {
public void printFlavor() { System.out.println("spicy"); }
}
public class Lunch {
public static void main(String[] args) {
Food pepper = new Pepper();
pepper.printFlavor();
}
}
Select one:
a. bland
b. bland
spicy
c. no output
d. spicy
e. the program does not compile
2.What is the output of the following Java program?
abstract class Food {
abstract void printFlavor();
}
class Pepper extends Food {
void printFlavor() { System.out.println("spicy"); }
}
public class Lunch {
public static void main(String[] args) {
Food pepper = new Food();
pepper.printFlavor();
}
}
Select one:
a. bland
b. bland
spicy
c. no output
d. spicy
e. the program does not compile
3.What is the output of the following Java program?
class Food {
String flavor = "bland";
void printFlavor() { System.out.println(flavor); }
}
class Pepper extends Food {
String flavor = "spicy";
void printFlavor() { System.out.println(flavor); }
}
public class Lunch {
public static void main(String[] args) {
Food lunch = new Pepper();
lunch.printFlavor();
}
}
Select one:
a. bland
b. bland
spicy
c. no output
d. spicy
e. the program does not compile
4.What is the output of the following Java program?
class Food {
Food() { printFlavor(); }
void printFlavor() { System.out.println("bland"); }
}
class Pepper extends Food {
void printFlavor() { System.out.println("spicy"); }
}
public class Lunch {
public static void main(String[] args) {
Food lunch = new Pepper();
}
}
Select one:
a. bland
b. bland
spicy
c. no output
d. spicy
e. the program does not compile
itur laoreet. Nam risus ante, dapib
m ipsum dolor sit amet, consectetur
ultrices a
inia pulvina
gue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus anteUnlock full access to Course Hero
Explore over 16 million step-by-step answers from our library
Subscribe to view answer