SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Class 10
Computer Application
Chapter 3
User Defined Methods
in java
Presented by,
Siva Shankari Rajan,
CPSV
What is method?
A method or a
function is a sequence
of statements
grouped together and
given a name
This group of statements
can be called at any point in
the program using its name
to perform a specific task.
Why to use
methods?
Methods are used
in the programs for
various reason
To code complexity
To hide the details
For reusable code
To simplify program
maintenance
Method declaration
Method Declaration
It declare either
specifies the type of
the value which a
method will return
or
use the keyword void
to indicate that it will
not return any value
Method Declaration
A method consists of
two parts:
• Header part
• Body part.
The method header is the
first line of the function
declaration or definition.
The method body contains a
set of statements for related
operations written in curly
brackets.
Method Declaration
Header part :
1. Modifier
2. Return type
3. Method name
4. Parameter list
 Modifier tells the compiler how to
call the method.
 Return type specifies the type of
value returned from a function.
 Function name is the name
assigned to the method.
 Parameter list is comma-
separated list of variables of a
function.
The methods are of
two types:
1. Built in method
2. User defined
method
The built-in methods are
pre-defined methods
stored in the Java library.
The user-defined methods
are defined by the
programmers as per their
need.
A Method exists in
three different forms
within a program:
Method prototype
Method definition
Method call
Method Prototype
Method Definition
Function prototype is the first line of the method
definition ended by semicolon that tells the
program about the signatures of the function.
A method is called (invokedorexecuted)by
providing the method name along with the
argument list enclosed in the parenthesis.
Method Call
A method is called (invokedorexecuted)by
providing the method name along with the
argument list enclosed in the parenthesis.
Method Signature
It is basically refers to
the number and types
of the arguments in the
method.
It itself is used to refer
to a method prototype.
Public class drawing
{
Public void draw(String s)
{….}
Public void draw(int i)
{….}
Public void draw(double d)
{….}
Public void draw(int I, double s)
{….}
}
Is also called method overloaded
Arguments
An argumentis a value itself
that is passed to a method when
it is executed
Parameters
the parameter list appears
between the parentheses
following the method name.
Public void main(){
A=obj.Sum(5,8);//5,8 arearguments being
passed toparameter x
andy
----------
----------
}
Float Sum(int x, int y){
Float add=(x+y)/2; //x andy
areparameter
Return add;
}
Actual parameter
Theparameter that appear in a
method call statement arecalled
actual parameter.
Formal Parameter
the parameter that appear in the
function definition are called
formal parameter.
Public int sum(int a, int b)
{
return a+b; //a andbareformal parameter
}
int length=10;
int breadth=5;
int add=sum(length,breadth);
//areactual parameter
How to access
Method?
A method can be
accessed or called by
providing the name of
the method followed
by parameter enclosed
in parentheses.
Class callmethod
{
Public double area(double a, double b)
{
double x;
x=a*b;
return x;
}
Public void accessingmethod()
{double x,y,z;
x=3.0;y=9.3;
z=area(x,y);//calling method area()
System.out.println(z);
Pure functions
Thefunction which returnvalues
and do not change state are
called purefunction.
impure function
Thefunction which changesthe
state of objects is called impure
function
class add
{
private double a,b,c;
public add()
{a=10.0;b=10.0;c=1.0;}
public double sum()
{
return(a+b);// purefunction, return exact value
}
public void sum1()
{c=a+b;//impurefunction, value ofcvaries
System.out.println(c);}
Passing values to
method
Values can be passed
in the following two
ways,
1. Call by value
2. Call by address
(reference)
Call by value
Themethod createsits newset of variables to copy the
value of actual parameters andworks with them
Call by address
Reference of the actual parameters is passed on to the
method. No newset ofvariables is created.
Call by value
class passbyvalue
{
public void changed()
{
int a=12;
System.out.println(“original value=“+a);
System.out.println(“changed
value=“+value(a));
System.out.println(“again value=“+a);
}
public static int value(int x)
{
x=10;
return x;
}
}
Call by Reference
class Test
{
int x;
Test(int i) { x = i; }
Test() { x = 0; }
}
class Main {
public static void main(String[] args) {
Test t = new Test(5); // t is a reference
change(t);
System.out.println(t.x);
}
public static void change(Test t)
{
t = new Test();
t.x = 10;
}
}
RecursiveMethod
Recursionin java is a
process in which a method
calls itself continuously.
It makes the code compact
but complex to understand.
public class RecursionExample1 {
static void p(){
System.out.println("hello");
p();
}
public static void main(String[] args) {
p();
}
}
Method overloading
Method overloading
means that there are
more than one
function doing
different kinds of jobs
but have same name.
this process is also
known as
polymorphism.
Public class calc
{
Public void sum(int s,int v)
{System.out.println(s+v);
}
Public void sum(int I, int j,int k)
{
System.out.println(i+j+k);
}
Public static void main(string args[])
{
calc ob=new calc();
Ob.sum(7,8);
Ob.sum(4,5,7);}
}
Thanks for watching

Weitere ähnliche Inhalte

Was ist angesagt? (20)

16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Python programming : Control statements
Python programming : Control statementsPython programming : Control statements
Python programming : Control statements
 
Function in c program
Function in c programFunction in c program
Function in c program
 
python Function
python Function python Function
python Function
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
virtual function
virtual functionvirtual function
virtual function
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Function in c
Function in cFunction in c
Function in c
 
constructors in java ppt
constructors in java pptconstructors in java ppt
constructors in java ppt
 
Command line arguments.21
Command line arguments.21Command line arguments.21
Command line arguments.21
 
C++ string
C++ stringC++ string
C++ string
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java package
Java packageJava package
Java package
 

Ähnlich wie User Defined Methods in Java: Class 10 Computer Application Chapter 3

EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...vekariyakashyap
 
Module 4 : methods & parameters
Module 4 : methods & parametersModule 4 : methods & parameters
Module 4 : methods & parametersPrem Kumar Badri
 
Java Foundations: Methods
Java Foundations: MethodsJava Foundations: Methods
Java Foundations: MethodsSvetlin Nakov
 
C programming session 08
C programming session 08C programming session 08
C programming session 08Vivek Singh
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloadingankush_kumar
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Abou Bakr Ashraf
 
Explain Delegates step by step.
Explain Delegates step by step.Explain Delegates step by step.
Explain Delegates step by step.Questpond
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6sotlsoc
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4dplunkett
 

Ähnlich wie User Defined Methods in Java: Class 10 Computer Application Chapter 3 (20)

EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
C# p8
C# p8C# p8
C# p8
 
Module 4 : methods & parameters
Module 4 : methods & parametersModule 4 : methods & parameters
Module 4 : methods & parameters
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Java Foundations: Methods
Java Foundations: MethodsJava Foundations: Methods
Java Foundations: Methods
 
C programming session 08
C programming session 08C programming session 08
C programming session 08
 
Functions
FunctionsFunctions
Functions
 
Java execise
Java execiseJava execise
Java execise
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
Ch06
Ch06Ch06
Ch06
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
 
C language 3
C language 3C language 3
C language 3
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Function in c
Function in cFunction in c
Function in c
 
Explain Delegates step by step.
Explain Delegates step by step.Explain Delegates step by step.
Explain Delegates step by step.
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
 
Method parameters in c#
Method parameters in c#Method parameters in c#
Method parameters in c#
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4
 

Kürzlich hochgeladen

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 

Kürzlich hochgeladen (20)

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 

User Defined Methods in Java: Class 10 Computer Application Chapter 3

  • 1. Class 10 Computer Application Chapter 3 User Defined Methods in java Presented by, Siva Shankari Rajan, CPSV
  • 2. What is method? A method or a function is a sequence of statements grouped together and given a name This group of statements can be called at any point in the program using its name to perform a specific task.
  • 3. Why to use methods? Methods are used in the programs for various reason To code complexity To hide the details For reusable code To simplify program maintenance
  • 5. Method Declaration It declare either specifies the type of the value which a method will return or use the keyword void to indicate that it will not return any value
  • 6. Method Declaration A method consists of two parts: • Header part • Body part. The method header is the first line of the function declaration or definition. The method body contains a set of statements for related operations written in curly brackets.
  • 7. Method Declaration Header part : 1. Modifier 2. Return type 3. Method name 4. Parameter list  Modifier tells the compiler how to call the method.  Return type specifies the type of value returned from a function.  Function name is the name assigned to the method.  Parameter list is comma- separated list of variables of a function.
  • 8. The methods are of two types: 1. Built in method 2. User defined method The built-in methods are pre-defined methods stored in the Java library. The user-defined methods are defined by the programmers as per their need.
  • 9. A Method exists in three different forms within a program: Method prototype Method definition Method call
  • 10. Method Prototype Method Definition Function prototype is the first line of the method definition ended by semicolon that tells the program about the signatures of the function. A method is called (invokedorexecuted)by providing the method name along with the argument list enclosed in the parenthesis.
  • 11. Method Call A method is called (invokedorexecuted)by providing the method name along with the argument list enclosed in the parenthesis.
  • 12. Method Signature It is basically refers to the number and types of the arguments in the method. It itself is used to refer to a method prototype. Public class drawing { Public void draw(String s) {….} Public void draw(int i) {….} Public void draw(double d) {….} Public void draw(int I, double s) {….} } Is also called method overloaded
  • 13. Arguments An argumentis a value itself that is passed to a method when it is executed Parameters the parameter list appears between the parentheses following the method name. Public void main(){ A=obj.Sum(5,8);//5,8 arearguments being passed toparameter x andy ---------- ---------- } Float Sum(int x, int y){ Float add=(x+y)/2; //x andy areparameter Return add; }
  • 14. Actual parameter Theparameter that appear in a method call statement arecalled actual parameter. Formal Parameter the parameter that appear in the function definition are called formal parameter. Public int sum(int a, int b) { return a+b; //a andbareformal parameter } int length=10; int breadth=5; int add=sum(length,breadth); //areactual parameter
  • 15. How to access Method? A method can be accessed or called by providing the name of the method followed by parameter enclosed in parentheses. Class callmethod { Public double area(double a, double b) { double x; x=a*b; return x; } Public void accessingmethod() {double x,y,z; x=3.0;y=9.3; z=area(x,y);//calling method area() System.out.println(z);
  • 16. Pure functions Thefunction which returnvalues and do not change state are called purefunction. impure function Thefunction which changesthe state of objects is called impure function class add { private double a,b,c; public add() {a=10.0;b=10.0;c=1.0;} public double sum() { return(a+b);// purefunction, return exact value } public void sum1() {c=a+b;//impurefunction, value ofcvaries System.out.println(c);}
  • 17. Passing values to method Values can be passed in the following two ways, 1. Call by value 2. Call by address (reference) Call by value Themethod createsits newset of variables to copy the value of actual parameters andworks with them Call by address Reference of the actual parameters is passed on to the method. No newset ofvariables is created.
  • 18. Call by value class passbyvalue { public void changed() { int a=12; System.out.println(“original value=“+a); System.out.println(“changed value=“+value(a)); System.out.println(“again value=“+a); } public static int value(int x) { x=10; return x; } }
  • 19. Call by Reference class Test { int x; Test(int i) { x = i; } Test() { x = 0; } } class Main { public static void main(String[] args) { Test t = new Test(5); // t is a reference change(t); System.out.println(t.x); } public static void change(Test t) { t = new Test(); t.x = 10; } }
  • 20. RecursiveMethod Recursionin java is a process in which a method calls itself continuously. It makes the code compact but complex to understand. public class RecursionExample1 { static void p(){ System.out.println("hello"); p(); } public static void main(String[] args) { p(); } }
  • 21. Method overloading Method overloading means that there are more than one function doing different kinds of jobs but have same name. this process is also known as polymorphism. Public class calc { Public void sum(int s,int v) {System.out.println(s+v); } Public void sum(int I, int j,int k) { System.out.println(i+j+k); } Public static void main(string args[]) { calc ob=new calc(); Ob.sum(7,8); Ob.sum(4,5,7);} }