Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualCuajin

Posted 27 March 2012 - 09:35 PM

Thank you very much.

#2Cuajin

Posted 27 March 2012 - 08:53 PM

Thank you very much.

How would I call the toString from Point3D class from a test class? For example:
public class Test
{
	  public static void main(String[] args)
	  {	  
		 // list is a list of Shapes
	     Shape [] list = {new Sphere(1, 1, 1, 5) };
		 System.out.println ( ((Shape)list[0]).toString() );
	  }
}

I want the output to be: "I'm inside the point3D"   // code is above in the Point3D class.
But it is printing the toString from the Sphere class instead.

How do I downcast or upcast to do this?

#1Cuajin

Posted 27 March 2012 - 08:51 PM

Thank you very much.

How would I call the toString from Point3D class from a test class? For example:
public class Test
{
	  public static void main(String[] args)
	  {	   
  // list is a list of Shapes
  Shape [] list = {new Sphere(1, 1, 1, 5) };
System.out.println ( ((Shape)list[0]).toString() );
	  }
}

I want the output to be: "I'm inside the point3D"    // code is above in the Point3D class.

How do I downcast or upcast to do this?

PARTNERS