today is November 22, 2008

Copyright © 2002-2008 freeforessays.com. All rights reserved.

Search Free For Essays


 

Search Tips


TOPICS REGISTER FAQ DIRECTORY

Essay Information

Words: 2591
Rating: None
Pages: 10.4
submitted by: gurbir1

If you think this essay shouldn't be here then

 

Register & Login

You are viewing a preview of this essay to view the full text you must Register & Login.

If you don't currently have a login then Register here



Username:

Password:

 

  Click for Essays with Citations

Topics > Science > AIDS


Featured Papers from Direct Essays

1. AIDS

2. AIDS

3. Aids in the US

4. Aids

5. Aids



AIDS

Return value The return value is a required element of the method signature. The return type declares what type of data (reference data type or primitive data type) will be returned by the method to the caller of this method. If the method has no data to return, as in the case of many setter or mutator methods, then the keyword void must be used. If the method returns a specific data type then this must be defined using the keyword return in the body of the method. The keyword return is used in two different formats: return value; return; In the first format, the return type identifies the data that is to be returned such as x, a reference to a primitive or another object, or this, a reference to the current object whose method is called. The compiler automatically provides the second format (at the end of the method block) format when the return type of the method is void. There are special occasions when programmers will use the second format. A later example uses this format to end the method abruptly and exit from the method before all the instructions have been completed. This may occur if some condition was not met for the code to continue execution. Specific Java-types are primitives and Java classes. A common mistake made in method coding is to describe the return type as the reference variable to an object or primitive. If a method returns a reference to an object, the method syntax only declares the class of the object and not the object reference. If a method returns a primitive, the method syntax declares the primitive data type and not the variable name. A method can only return one value. A return statement can return a value referenced by a variable or the result of an expression. In all instances, the data type of the values must be assignment compatible to the data-type declared as the return type in the method definition. The sample code shown for the LabelText class demonstrates the return type void. When the print() method of the LabelText class is called in the main method, the object String variable label is printed. Since the return type for this method is void, the print() method does not return any value when used. Note that there is no return statement in the print() method. A method can return a reference to a primitive or any Java class. The sample code shown for the MyStock class demonstrates the return type primitive. The sample code shown for the modified MyStock class demonstrates the return type Java-class. In this code, the keyword this is used as a placeholder for the current objects whose methods are called. At compile time, no objects are created. The keyword this serves as a placeholder variable for the compiler, which will be assigned as an object reference at runtime. Section 5.7 of this chapter will explore the use of this in further detail. In addition to declaring the return value, the body of the method must include the return statement in the code. The sample code shown in Figure demonstrates the correct and incorrect placement of the return statement 5.6.5 Method arguments The method arguments can be omitted by declaring the method to have no arguments using the syntax ( ).


To link to this page, copy the following code to your site:



All Papers Are For Research And Reference Purposes Only!
You may not turn these papers in as your own! You must cite our web site as your source!

Exchange Links With Free For Essays