OOPS in JAVA 3
Methods in Java
Method describe behavior of an object. A method is a collection of statements that are group together to perform an operation.
Syntax:
modifier return-type methodName ( parameter-list )
{
//body of method
}
Example of a Method
public String getName(String st)
{
String name="betheDeveloper.com";
name=name+st;
return name;
}
Modifier : Modifier are access type of method and its optional to use.
Return Type : A method may return value.
Method name : Actual name of the method.
Parameter : Value passed to a method.
Method body : Collection of statement that defines what method does.
Parameter Vs. Argument:
Parameter is variable defined by a method that receives value when the method is called. Parameter are always local to the method they dont have scope outside the method. While argument is a value that is passed to a method when it is called.
The finalize( ) Method:
It is possible to define a method that will be called just before an object's final destruction by the garbage collector. This method is called finalize( ), and it can be used to ensure that an object terminates cleanly.
Inside the finalize( ) method, you will specify those actions that must be performed before an object is destroyed.
The finalize( ) method has this general form:
protected void finalize( )
{
// finalization code here
}
Here, the keyword protected is a specifier that prevents access to finalize( ) by code defined outside its class.
No comments:
Post a Comment
Hai , Post your comment . (required, Bugs, Errors )