-1

Can anyone explain what the purpose of the ints are in Rectangle center and Rectangle obstacle? I already understand that an int is a positive or negative whole number. Also why don't I need any ints in Rectangle left and Rectangle right if they are needed in center and obstacle? I'm still new to this so if anyone thinks I should include more code just let me know.

Rectangle left = new Rectangle(0,0,WIDTH/9,HEIGHT);
Rectangle right = new Rectangle((WIDTH/9)*8,0,WIDTH/9,HEIGHT);

Rectangle center = new Rectangle((int)((WIDTH/9)* 2.5),(int)((HEIGHT/9)*2.5),(int)  
((WIDTH/9)*5),(HEIGHT/9)*4);
Rectangle obstacle = new Rectangle(WIDTH/2,(int)((HEIGHT/9)*7),
WIDTH/10,HEIGHT/9);
Martin Marino
  • 375
  • 2
  • 5
  • 14

1 Answers1

1

Java is a strongly typed language, which means every variable has a data type. However, via polymorphism you can use the information from one data type and handle it as a different one. Examples of this in Java are interfaces & subclasses. You can do this conversion either by implicit or explicit casting. That is what is shown here.

When you use a primitive data type or object name in parentheses before another variable, it casts to another compatible type.

As long as the internal data is compatible, you can convert the type to something else. For example, if the Object in question here was a String:

if(s instanceof String) {
String t = (String)s;
}
David B
  • 2,688
  • 18
  • 25
  • I'm sorry can you dumb this down a little bit for me a posted a new question with some extra code. Any help is greatly appreciated. – Martin Marino May 23 '12 at 21:37
  • I have updated the answer with a bit more information of types. If this helps you, remember to accept the answer by hitting the green check mark! – David B May 23 '12 at 22:04