Method Overloading
Method Overloading
class OverloadDemo {
void test() { class Overload {
System.out.println("No parameters"); public static void main(String args[]) {
} OverloadDemo ob = new
OverloadDemo();
// Overload test for two integer parameters. int i= 50;
void test(int a, int b) { double result;
System.out.println("a and b: " + a + " " + b); ob.test();
} ob.test(i); //will it execute ?
ob.test(10, 20);
// overload test for a double parameter result = ob.test(123.25);
double test(double a) { System.out.println("Result of
System.out.println("double a: " + a); ob.test(123.25): " + result);
return a*a; }
} }
}
The object will continue to exist as long as there is a reference to it somewhere in your
program.
When there are no references to it, the object will be reclaimed the next time garbage
collection takes place
L.Sumathi ,AP/CSE ,GCT 4
Call by Value ,Call by Reference
// Objects are passed by reference.
// Primitive types are passed by value. class Test {
class Test { int a, b;
void meth(int i, int j) { Test(int i, int j) {
i *= 2; a = i;
j /= 2; b = j;
} }
} void meth(Test o) {
class CallByValue { o.a *= 2;
public static void main(String args[]) { o.b /= 2;
Test ob = new Test(); }
int a = 15, b = 20; }
System.out.println("a and b before call: " + class CallByRef {
a + " " + b); public static void main(String args[]) {
ob.meth(a, b); Test ob = new Test(15, 20);
System.out.println("a and b after call: " + System.out.println("ob.a and ob.b before call: " +
a + " " + b); ob.a + " " + ob.b);
} ob.meth(ob);
} System.out.println("ob.a and ob.b after call: " +
ob.a + " " + ob.b);
}
} ,AP/CSE ,GCT
L.Sumathi 5
Reference
https://www.javatpoint.com/
https://nptel.ac.in/noc/courses/noc20/SEM1/noc20-cs08/
➢geeksforgeeks.org/differences-jdk-jre-jvm/
➢https://www.codejava.net/java-se/java-se-versions-
history