SlideShare a Scribd company logo
11
Most read
14
Most read
15
Most read
Method overloading, recursion , passing
and returning objects from method, new
operator
Prepared By : -
Jainam Kapadiya
Contents of the Presentation
 Method and Method overloading
 How to overload method in JAVA?
 Method overloading Examples of program.
New operator
Recursion
 Passing and returning objects from methods.
Method overloading, recursion, passing and returning objects from method, new operator
Method overloading, recursion, passing and returning objects from method, new operator
Method overloading, recursion, passing and returning objects from method, new operator
Method overloading, recursion, passing and returning objects from method, new operator
Method overloading, recursion, passing and returning objects from method, new operator
 The new operator allocates memory dynamically for an
object. Here is the general form to use new operator in Java.
New Operator
class-var = new classname();
 Here, class-var is the variable of the class type being
created. The classname is the name of the class that is being
instantiated.
 The class name followed by the parentheses determines
the constructor for the class. A constructor defines what
occurs whenever an object of a class is created.
 Constructors are an crucial part of all the classes and have
many significant attributes.
Method overloading, recursion, passing and returning objects from method, new operator
public class Recursion
{
static int factorial(int n)
{
if (n == 1)
return 1;
else
return(n * factorial(n-1));
}
public static void main(String[] args)
{
System.out.println("Factorial of 5 is: "+factorial(5));
}
}
O/P:-
Factorial of 5 is: 120
RECURSION PROGRAM
Method overloading, recursion, passing and returning objects from method, new operator
Example:-
// Java program to demonstrate objects
// passing to methods.
class ObjectPassDemo
{
int a, b;
ObjectPassDemo(int i, int j)
{
a = i;
b = j;
}
// return true if o is equal to the invoking
// object notice an object is passed as an
// argument to method
boolean equalTo(ObjectPassDemo o)
{
return (o.a == a && o.b == b);
}
}
// Driver class
public class Test
{
public static void main(String args[])
{
ObjectPassDemo ob1 = new ObjectPassDemo(100, 22);
ObjectPassDemo ob2 = new ObjectPassDemo(100, 22);
ObjectPassDemo ob3 = new ObjectPassDemo(-1, -1);
System.out.println("ob1 == ob2: " + ob1.equalTo(ob2));
System.out.println("ob1 == ob3: " + ob1.equalTo(ob3));
}
}
Output:
ob1 == ob2: true
ob1 == ob3: false
Method overloading, recursion, passing and returning objects from method, new operator
// This method returns an object
Test incrByTen()
{
Test temp =
new Test(a+10);
return temp;
}
}
// Driver class
class returningobject
{
public static void main(String args[])
{
Test ob1 = new Test(2);
Test ob2;
ob2 = ob1.incrByTen();
System.out.println("ob1.a: " + ob1.a);
System.out.println("ob2.a: " + ob2.a);
}
}
Output:
ob1.a: 2 ob2.a: 12

More Related Content

PPTX
This keyword in java
Hitesh Kumar
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PPT
Method overriding
Azaz Maverick
 
PPTX
OOP Introduction with java programming language
Md.Al-imran Roton
 
PPT
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
PPTX
Operator overloading
Ramish Suleman
 
PPTX
oops concept in java | object oriented programming in java
CPD INDIA
 
PPTX
Super keyword in java
Hitesh Kumar
 
This keyword in java
Hitesh Kumar
 
Classes, objects in JAVA
Abhilash Nair
 
Method overriding
Azaz Maverick
 
OOP Introduction with java programming language
Md.Al-imran Roton
 
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
Operator overloading
Ramish Suleman
 
oops concept in java | object oriented programming in java
CPD INDIA
 
Super keyword in java
Hitesh Kumar
 

What's hot (20)

ODP
OOP java
xball977
 
PPTX
Interface in java
PhD Research Scholar
 
PPT
Abstract class
Tony Nguyen
 
PPT
Java interfaces & abstract classes
Shreyans Pathak
 
PPTX
Polymorphism presentation in java
Ahsan Raja
 
PPT
Applet life cycle
myrajendra
 
PPTX
Inheritance
Sapna Sharma
 
PPTX
Asymptotic notations
Nikhil Sharma
 
PPTX
Procedural vs. object oriented programming
Haris Bin Zahid
 
PPTX
Advance Java Topics (J2EE)
slire
 
PPTX
Inheritance in java
Tech_MX
 
PPTX
Constructor overloading & method overloading
garishma bhatia
 
PPT
Java collections concept
kumar gaurav
 
PPTX
Java abstract class & abstract methods
Shubham Dwivedi
 
PPTX
Data types in java
HarshitaAshwani
 
PDF
Introduction to OpenMP
Akhila Prabhakaran
 
PPT
Jsp ppt
Vikas Jagtap
 
PPTX
Method Overloading in Java
Sonya Akter Rupa
 
PDF
Applets
Prabhakaran V M
 
OOP java
xball977
 
Interface in java
PhD Research Scholar
 
Abstract class
Tony Nguyen
 
Java interfaces & abstract classes
Shreyans Pathak
 
Polymorphism presentation in java
Ahsan Raja
 
Applet life cycle
myrajendra
 
Inheritance
Sapna Sharma
 
Asymptotic notations
Nikhil Sharma
 
Procedural vs. object oriented programming
Haris Bin Zahid
 
Advance Java Topics (J2EE)
slire
 
Inheritance in java
Tech_MX
 
Constructor overloading & method overloading
garishma bhatia
 
Java collections concept
kumar gaurav
 
Java abstract class & abstract methods
Shubham Dwivedi
 
Data types in java
HarshitaAshwani
 
Introduction to OpenMP
Akhila Prabhakaran
 
Jsp ppt
Vikas Jagtap
 
Method Overloading in Java
Sonya Akter Rupa
 
Ad

Similar to Method overloading, recursion, passing and returning objects from method, new operator (20)

PPTX
Unit No 3 Inheritance annd Polymorphism.pptx
DrYogeshDeshmukh1
 
PPTX
Chap-2 Classes & Methods.pptx
chetanpatilcp783
 
PPTX
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
Sagar Verma
 
PPTX
Object oriented concepts
Gousalya Ramachandran
 
PPTX
Framework prototype
DevMix
 
PPTX
Framework prototype
DevMix
 
PPTX
Framework prototype
DevMix
 
PDF
Object Oriented Programming in PHP
wahidullah mudaser
 
PPT
Sonu wiziq
Sonu WIZIQ
 
PPTX
Basics to java programming and concepts of java
1747503gunavardhanre
 
PPSX
Java session4
Jigarthacker
 
PPTX
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 
PDF
OOPs & Inheritance Notes
Shalabh Chaudhary
 
PPT
Java tutorial for Beginners and Entry Level
Ramrao Desai
 
PPTX
‫Chapter3 inheritance
Mahmoud Alfarra
 
PDF
Java Basic day-2
Kamlesh Singh
 
PPTX
constructer.pptx
Nagaraju Pamarthi
 
PDF
OOPs Concepts - Android Programming
Purvik Rana
 
PDF
Java Interview Questions PDF By ScholarHat
Scholarhat
 
PPTX
OOP with Java - continued
RatnaJava
 
Unit No 3 Inheritance annd Polymorphism.pptx
DrYogeshDeshmukh1
 
Chap-2 Classes & Methods.pptx
chetanpatilcp783
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
Sagar Verma
 
Object oriented concepts
Gousalya Ramachandran
 
Framework prototype
DevMix
 
Framework prototype
DevMix
 
Framework prototype
DevMix
 
Object Oriented Programming in PHP
wahidullah mudaser
 
Sonu wiziq
Sonu WIZIQ
 
Basics to java programming and concepts of java
1747503gunavardhanre
 
Java session4
Jigarthacker
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 
OOPs & Inheritance Notes
Shalabh Chaudhary
 
Java tutorial for Beginners and Entry Level
Ramrao Desai
 
‫Chapter3 inheritance
Mahmoud Alfarra
 
Java Basic day-2
Kamlesh Singh
 
constructer.pptx
Nagaraju Pamarthi
 
OOPs Concepts - Android Programming
Purvik Rana
 
Java Interview Questions PDF By ScholarHat
Scholarhat
 
OOP with Java - continued
RatnaJava
 
Ad

More from JAINAM KAPADIYA (8)

PDF
CLASSIFICATION OF DEBUGGERS
JAINAM KAPADIYA
 
PDF
Clementine tool
JAINAM KAPADIYA
 
PDF
Zed Attack Proxy (ZAP)
JAINAM KAPADIYA
 
PPTX
Software Engineering Layered Technology Software Process Framework
JAINAM KAPADIYA
 
PDF
Android Application Components
JAINAM KAPADIYA
 
PDF
Symmetric Cipher Model, Substitution techniques, Transposition techniques, St...
JAINAM KAPADIYA
 
PDF
Computer graphics practical(jainam)
JAINAM KAPADIYA
 
PPTX
Corruption in india
JAINAM KAPADIYA
 
CLASSIFICATION OF DEBUGGERS
JAINAM KAPADIYA
 
Clementine tool
JAINAM KAPADIYA
 
Zed Attack Proxy (ZAP)
JAINAM KAPADIYA
 
Software Engineering Layered Technology Software Process Framework
JAINAM KAPADIYA
 
Android Application Components
JAINAM KAPADIYA
 
Symmetric Cipher Model, Substitution techniques, Transposition techniques, St...
JAINAM KAPADIYA
 
Computer graphics practical(jainam)
JAINAM KAPADIYA
 
Corruption in india
JAINAM KAPADIYA
 

Recently uploaded (20)

PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Software Development Company | KodekX
KodekX
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Software Development Company | KodekX
KodekX
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 

Method overloading, recursion, passing and returning objects from method, new operator

  • 1. Method overloading, recursion , passing and returning objects from method, new operator Prepared By : - Jainam Kapadiya
  • 2. Contents of the Presentation  Method and Method overloading  How to overload method in JAVA?  Method overloading Examples of program. New operator Recursion  Passing and returning objects from methods.
  • 8.  The new operator allocates memory dynamically for an object. Here is the general form to use new operator in Java. New Operator class-var = new classname();  Here, class-var is the variable of the class type being created. The classname is the name of the class that is being instantiated.  The class name followed by the parentheses determines the constructor for the class. A constructor defines what occurs whenever an object of a class is created.  Constructors are an crucial part of all the classes and have many significant attributes.
  • 10. public class Recursion { static int factorial(int n) { if (n == 1) return 1; else return(n * factorial(n-1)); } public static void main(String[] args) { System.out.println("Factorial of 5 is: "+factorial(5)); } } O/P:- Factorial of 5 is: 120 RECURSION PROGRAM
  • 12. Example:- // Java program to demonstrate objects // passing to methods. class ObjectPassDemo { int a, b; ObjectPassDemo(int i, int j) { a = i; b = j; } // return true if o is equal to the invoking // object notice an object is passed as an // argument to method boolean equalTo(ObjectPassDemo o) { return (o.a == a && o.b == b); } }
  • 13. // Driver class public class Test { public static void main(String args[]) { ObjectPassDemo ob1 = new ObjectPassDemo(100, 22); ObjectPassDemo ob2 = new ObjectPassDemo(100, 22); ObjectPassDemo ob3 = new ObjectPassDemo(-1, -1); System.out.println("ob1 == ob2: " + ob1.equalTo(ob2)); System.out.println("ob1 == ob3: " + ob1.equalTo(ob3)); } } Output: ob1 == ob2: true ob1 == ob3: false
  • 15. // This method returns an object Test incrByTen() { Test temp = new Test(a+10); return temp; } } // Driver class class returningobject { public static void main(String args[]) { Test ob1 = new Test(2); Test ob2; ob2 = ob1.incrByTen(); System.out.println("ob1.a: " + ob1.a); System.out.println("ob2.a: " + ob2.a); } } Output: ob1.a: 2 ob2.a: 12