Question: Consider the following class declarations. public class Publication { private String title; public Publication ( ) { title = Generic; } public Publication ( String

Consider the following class declarations.
public class Publication
{
private String title;
public Publication()
{
title = "Generic";
}
public Publication(String t)
{
title = t;
}
}
public class Book extends Publication
{
public Book()
{
super();
}
public Book(String t)
{
super(t);
}
}
The following code segment appears in a method in another class.
Book myBook = new Book("Adventure Story"); // Line 1
Book yourBook = new Book(); // Line 2
Which of the following best describes the result of executing the code segment?
Responses
The variable myBook is assigned a reference to a new Book object created using the one-argument Book constructor, which uses super to set myBooks title attribute to "Adventure Story". The variable yourBook is assigned a reference to a new Book object created using the no-argument Book constructor, which uses super to set yourBooks title attribute to an empty string.
The variable myBook is assigned a reference to a new Book object created using the one-argument Book constructor, which uses super to set myBook s title attribute to "Adventure Story" . The variable yourBook is assigned a reference to a new Book object created using the no-argument Book constructor, which uses super to set yourBook s title attribute to an empty string.
The variable myBook is assigned a reference to a new Book object created using the no-argument Book constructor, which uses super to set myBooks title attribute to "Generic". The variable yourBook is assigned a reference to a new Book object created using super to call to the Publication no-argument constructor to set yourBooks title attribute to "Generic".
The variable myBook is assigned a reference to a new Book object created using the no-argument Book constructor, which uses super to set myBook s title attribute to "Generic" . The variable yourBook is assigned a reference to a new Book object created using super to call to the Publication no-argument constructor to set yourBook s title attribute to "Generic" .
The variable myBook is assigned a reference to a new Book object created using the one-argument Book constructor, which uses super to set myBooks title attribute to "Adventure Story". The variable yourBook is assigned a reference to a new Book object created using super to call to the Publication no-argument constructor to set yourBooks title attribute to "Generic".
The variable myBook is assigned a reference to a new Book object created using the one-argument Book constructor, which uses super to set myBook s title attribute to "Adventure Story" . The variable yourBook is assigned a reference to a new Book object created using super to call to the Publication no-argument constructor to set yourBook s title attribute to "Generic" .
A runtime error occurs in line 1 because the one-argument Publication constructor cannot be called from the one-argument Book constructor.
A runtime error occurs in line 1 because the one-argument Publication constructor cannot be called from the one-argument Book constructor.
A runtime error occurs in line 2 because the no-argument Publication constructor cannot be called from the no-argument Book constructor.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!