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).

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education