Some Java Topics
Some Java Topics
Lecture # 13
2
Void Keyword
• Allows us to create methods which do not return a value.
• Call to a void method must be a statement.
Example: Result:
3
Passing Parameters by Value
• While working under calling process, arguments is to be passed
• These should be in the same order as their respective parameters in the method
specification.
• Parameters can be passed by value or by reference.
• Passing Parameters by Value means calling a method with a parameter. Through this,
the argument value is passed to the parameter.
4
Passing Parameters by Value
• While working under calling process, arguments is to be passed
Example: Result:
5
Passing Parameters by Value
• While working under calling process, arguments is to be passed
Example: Result:
6
Method Overloading
• A class has two or more methods by the same name but different parameters, is
known as method overloading.
Example:
Result:
7
This Keyword
• this is a keyword in Java which is used as a reference to the object of the current class,
with in an instance method or a constructor.
• Using this you can refer the members of a class such as constructors, variables and
methods.
• The keyword this is used only within instance methods or constructors.
8
This Keyword
The keyword this is used to −
• Differentiate the instance variables from local variables if they have same names,
within a constructor or a method.
9
This Keyword
An example that uses this keyword to access the members of a class.
Result:
10
THANK YOU!