| The Java Course provides a general introduction to programming in Java . It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details. |

Home Interesting objects Objects as return types |
||
Objects as return typesYou can write methods that return objects. For example, findCenter takes a Rectangle as an argument and returns a Point that contains the coordinates of the center of the Rectangle: int x = box.x + box.width/2; int y = box.y + box.height/2; return new Point (x, y); } Notice that you can use new to create a new object, and then immediately use the result as a return value.
|
||