Show differencesHistory of post edits
#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:
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?
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:
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?
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?