Professional Documents
Culture Documents
CP - March 2, 2023
CP - March 2, 2023
impressions, my boy,
but concentrate yourself
upon details.
SIR ARTHUR CONAN DOYLE,
A Case of Identity (SHERLOCK
HOLMES)
Recall
• With inheritance the behavior
and data associated with the
child classes are always an
extension of the behavior and
data associated with the
parent class
In a child class you can
double demo(double a) {
System.out.println("double a: " + a);
return a*a;
}
}
class MethodOverloading {
public static void main (String [] a) {
Overload obj = new Overload();
double a;
}
}
class MethodOverloading {
public static void main (String args []) {
Overload Obj = new Overload();
double result;
// code here to demonstrate overloading
}
}
class MethodOverloading { class Overload {
public static void main (String args []) { void demo (int a) {
Overload Obj = new Overload(); System.out.println ("a: "
+ a);
double a;
}
int number=5;
Obj.demo(0.0); void demo (int a, int b) {
Obj.demo(number); System.out.println ("a and
Obj.demo(8,number); b: " + a + "," + b);
} }
}
double demo(double a) {
System.out.println("double a:
" + a);
return a*a;
}
}
Revise the MethodOverloading class so that it can receive
values from the user, to be used for the method calls.
Write the programs (Overload and Method Overloading)
in a 1-whole sheet of paper.
class MethodOverloading {
public static void main (String args []) {
Overload Obj = new Overload();
double result;
Obj .demo(10);
Obj .demo(10, 20);
result = Obj .demo(5.5);
System.out.println("O/P : " + result);
}
}