Using interfaces, you can specify similar behaviors for possibly disparate classes. Governments and companies worldwide are becoming increasingly concerned with carbon footprints (annual releases of carbon dioxide into the atmosphere) from buildings burning various types of fuels for heat, vehicles burning fuels for power, and the like. Many scientists blame these greenhouse gases for the phenomenon called global warming. Create three small classes unrelated by inheritance—classes Building, Car and Bicycle. Write an interface CarbonFootprint with a getCarbonFootprint method. Have each of your classes implement that interface, so that its getCarbonFootprint method prints out an appropriate message (e.g., this message from Building CarbonFoot). Write an application that creates objects of each of the three classes and one interface reference variable, assign each object to the interface reference variable, and then invoke each object’s getCarbonFootprint method by means of dynamic method dispatch. For each object, print a simple message (e.g., this message from Building CarbonFoot).

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 34SA
icon
Related questions
Question

(Java) Using interfaces, you can specify similar behaviors for possibly disparate classes.
Governments and companies worldwide are becoming increasingly concerned with carbon
footprints (annual releases of carbon dioxide into the atmosphere) from buildings burning
various types of fuels for heat, vehicles burning fuels for power, and the like. Many
scientists blame these greenhouse gases for the phenomenon called global warming. Create
three small classes unrelated by inheritance—classes Building, Car and Bicycle. Write an
interface CarbonFootprint with a getCarbonFootprint method. Have each of your classes
implement that interface, so that its getCarbonFootprint method prints out an appropriate
message (e.g., this message from Building CarbonFoot). Write an application that creates
objects of each of the three classes and one interface reference variable, assign each object
to the interface reference variable, and then invoke each object’s getCarbonFootprint
method by means of dynamic method dispatch. For each object, print a simple message
(e.g., this message from Building CarbonFoot).

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning