EBK OBJECTS FIRST WITH JAVA
EBK OBJECTS FIRST WITH JAVA
6th Edition
ISBN: 9780134478449
Author: KOLLING
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 11, Problem 1E

Explanation of Solution

Given: The network project version and the display method is in the Post class.

To find:

The display method is shifted into the class MessagePost and PhotoPost.

The result on compilation of the program.

Solution:

The program shows compile time error after shifting the display() method from Post class to MessagePost and PhotoPost.

The MessagePost and PhotoPost are the subclasses of Post class. The private members can access only from the member function of the same class. The display() method tries to access the private members of the Post class from the subclasses MessagePost and PhotoPost. Therefore, it shows compile time error. A public member function created in the Post class and calling that from the display method removes error.

It also shows error in NewsFeed class because the NewsFeed class calls the display() method with the object of type Post and the display method is not in the Post class. Hence, it shows compile time error.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Examine the getBalance method's header and body, and then evaluate how they stack up against those of the getPrice method. I'm confused as to the differences between the two.
Use the debugger to investigate the clock-display project. Set breakpoints in the ClockDisplay constructor and each of the methods, and then singlestep through them. Does it behave as you expected? Did this give you new insights? If so, what were they?
Try removing the return statement from the body of getPrice. What error message do you see now when you try compiling the class?
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education