|
This program explains the use of “this” keyword. “this” can be used inside any method to refer the current object. That is , “this” id always a reference to the object on which the method was invoked. This program explains one use of “this“ keyword. You may local variable (variable inside a class) , which may overlap with the names of class instance variable then local variable hides the instance variable. This name collision problem can be sol\ed using “this” as it refer directly to the object. Save this file as boxdemo8.java To Run this program, type following lines in command prompt: C:\>:javac boxdemo8.java C:\>:java boxdemo8 |
|
Next program demonstrate a new concept “overloading of methods”. Overloading of methods means to define two or methods within same class that share name, as long as their parameter declaration is different. This program use three constructor (method having same name as class used to initialize an object immediately upon creation) each having different parameters. Save this file as overload.java To Run this program, type following lines in command prompt: C:\>:javac overload.java C:\>:java overload |

|
Java Program:Demostrate the use of “this” keyword |



|
Java Program:Demonstrate concept “overloading of methods”. |
|
Next program demonstrate similar concept of “overloading of methods”. Overloading of methods means to define two or methods within same class that share name, as long as their parameter declaration is different. In this program, we have again used three constructor (method having same name as class used to initialize an object immediately upon creation) each having different parameters. This program also explains that java automatically convert an integer to double and that conversion can be used to resolve call. Save this file as overload2.java To Run this program, type following lines in command prompt: C:\>:javac overload2.java C:\>:java overload2 |
|
Java Program:Demonstrate concept “overloading of methods” with automatic conversion example. . |