3 Replies - 343 Views - Last Post: 21 February 2012 - 12:40 PM Rate Topic: -----

#1 tkess17  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 24-September 11

Memory Address Printing Out

Posted 21 February 2012 - 12:16 PM

public abstract class Shape
{
	protected String name;

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public abstract double getSurfaceArea();

	protected double normalize(double entry)
	{
		if (entry < 0)
			return 0.0;
		else
			return entry;
	}

	public String toString()
	{
		return getName() + "surface area: " + getSurfaceArea();
	}
}




public class Square extends Shape
{
	double length;

	public Square(double length)
	{
		this.length = length;
	}

	public double getSurfaceArea()
	{
		double squareSurfaceArea = length * length;
		return squareSurfaceArea;
	}
}



Anyone have any idea why the memory address would print out? I want the ToString method to print out but I can't seem to figure out the problem.

EDIT: Now it is printing out nullSurfaceArea: and then the correct number but I don't understand why it is printing out null.

This post has been edited by tkess17: 21 February 2012 - 12:18 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Memory Address Printing Out

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10180
  • View blog
  • Posts: 37,585
  • Joined: 27-December 08

Re: Memory Address Printing Out

Posted 21 February 2012 - 12:19 PM

It's printing out null b/c you probably haven't set the name at that point. So by default, name is initialized to null.
Was This Post Helpful? 1
  • +
  • -

#3 tkess17  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 24-September 11

Re: Memory Address Printing Out

Posted 21 February 2012 - 12:23 PM

Well I'm glad I wasn't thinking right. Yeah I figured it out. Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10180
  • View blog
  • Posts: 37,585
  • Joined: 27-December 08

Re: Memory Address Printing Out

Posted 21 February 2012 - 12:40 PM

Glad I could help! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1