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 PublicationString t
title t;
public class Book extends Publication
public Book
super;
public BookString t
supert;
The following code segment appears in a method in another class.
Book myBook new BookAdventure Story"; Line
Book yourBook new Book; Line
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 oneargument 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 noargument 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 oneargument 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 noargument 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 noargument 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 noargument constructor to set yourBooks title attribute to "Generic".
The variable myBook is assigned a reference to a new Book object created using the noargument 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 noargument constructor to set yourBook s title attribute to "Generic"
The variable myBook is assigned a reference to a new Book object created using the oneargument 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 noargument constructor to set yourBooks title attribute to "Generic".
The variable myBook is assigned a reference to a new Book object created using the oneargument 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 noargument constructor to set yourBook s title attribute to "Generic"
A runtime error occurs in line because the oneargument Publication constructor cannot be called from the oneargument Book constructor.
A runtime error occurs in line because the oneargument Publication constructor cannot be called from the oneargument Book constructor.
A runtime error occurs in line because the noargument Publication constructor cannot be called from the noargument Book constructor.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
