1. Flower rose = new Flower(); rose.smell(); 2. Fruit orange = new Fruit(); oran
ID: 3599113 • Letter: 1
Question
1. Flower rose = new Flower();
rose.smell();
2.
Fruit orange = new Fruit();
orange.smell();
3.
Plant lotus = new Fruit();
lotus.smell();
For each of the following code snippets, please indicate if the code shown would a. fail to compile, b. compile, but result in an error at runtime, or c. execute without an error. In this case, indicate what output you would see. public abstract class Plant f public void smel1) ( System.out.println("No smell"); public class Flower extends Plant public void smell) System.out.println("I smell good!); public class Fruit extends Plant ( public void sme110 ( System.out.println("I smell yummy!")Explanation / Answer
=========================================================
------------
Answer:
------------
c. execute without an error.
// 1.
Flower rose = new Flower();
rose.smell();
----------
output:
----------
I smell good!
-------------------
explanation:
-------------------
rose is an object of flower, Hence Flower smell method is executed and
I smell good! is printed on console.
// 2.
Fruit orange = new Fruit();
orange.smell();
-----------
output:
-----------
I smell yummy!
-------------------
explanation:
--------------------
orange is an object of fruit, Hence Fruit smell method is executed and
I smell yummy! is printed on console.
// 3.
Plant lotus = new Fruit();
lotus.smell();
-----------
output:
-----------
I smell yummy!
--------------------
explanation:
--------------------
lotus is an object of fruit, Hence Fruit smell method is executed and
I smell yummy! is printed on console.
Plant is abstract class, Hence Fruit smell method is executed.
=========================================================
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.