Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8026075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:22:08+00:00 2026-06-04T23:22:08+00:00

I am trying to do my assignment but I am having a problem instantiating

  • 0

I am trying to do my assignment but I am having a problem instantiating an object that has a String parameter. when I compile and run what I have of the application so far, it returns the String value of “Null” instead of what I expect it to.

This is my abstract Superclass

public abstract class Book
{
//Declaration of class variable
private String title;
protected double price;

// contructor for Book class objects
public Book(String bookTitle)
    {
        bookTitle = title;
    }
//method that gets and returns books title
public String getTitle()
    {
        return title;
    }
//method that gets and returns books price
public double getPrice()
    {
        return price;
    }
//abstract method with no parameters
public abstract void setPrice();
}

This is my subclass

public class Fiction extends Book
{
//subclass contructor
public Fiction(String bookTitle)
{
    //calling superclass constructor
    super(bookTitle);
}
//override annotation and setPrice method override
@Override
public void setPrice()
{
    price = 19.99;
}
}

This is my main method class where the object fictionBook is supposed to be instantiated with the title The White Unicorn. However, for some reason my println is printing out null instead

public class BookTester
{
//Main method
public static void main(String[] args)
{
    //Instantiate object
    Fiction fictionBook = new Fiction("The White Unicorn");
    NonFiction nonFictionBook = new NonFiction("Autobiography of Curtis Sizemore");
    //call to the setPrice() method
    fictionBook.setPrice();
    nonFictionBook.setPrice();
    //Print information on books
    System.out.println("The Fiction book titled \"" + fictionBook.getTitle() + "\"costs $" + fictionBook.getPrice());
}
}

I cannot figure out what the problem is. Can anyone assist me? I also have a subclass for the nonFiction book, but I have not gotten to that point yet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:22:10+00:00Added an answer on June 4, 2026 at 11:22 pm
    public Book(String bookTitle)
        {
            bookTitle = title;
        }
    

    You’re setting your parameter to the property value–perhaps backwards from what you intended?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a homework assignment where I have to use fork() but
I am trying to create a db that has a year attribute but I
I am trying to do an assignment but I'm having trouble with the first
I am trying to learn Java's threads in order to do an assignment, but
I'm trying to propagate an assignment to the data parameter of a sub-component through
I'm stuck trying to get something to work in an assignment. I have a
I have an assignment about fftw and I was trying to write a small
I have an assignment to use JavaBeans to create an online Banking application. I
I have an assignment that asks me to retrieve delimited text from form values.
The main problem I'm having is trying to get the total wins loses and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.