Name: Ahnaf Abid Tawsif
Id:21225103141
Sec:04
Intake:49
Course Title: Advance Programming
Course code: CSE 342
Submitted to,
Md. Mahbubur Rahman
Assit. Prof , Dept. of CSE BUBT
Submission Date:
27/03/2024
LAB REPORT 1: Write a Java program method overloading
will be implemented for Number of parameter will be
different.
CODE:
public class MethodOverloading {
public void display(int a) {
[Link]("One parameter method: " + a);
}
public void display(int a, int b) {
[Link]("Two parameters method: " + a + ", " + b);
}
public void display(int a, int b, int c) {
[Link]("Three parameters method: " + a + ", " + b + ", " + c);
}
public static void main(String[] args) {
MethodOverloading obj = new MethodOverloading();
[Link](10);
[Link](20, 30);
[Link](40, 50, 60);
}
}
OUTPUT
LAB REPORT 2: Write a Java program method overloading
will be implemented for Order of parameter will be
different.
CODE:
public class MethodOverloading {
public void display(int a, double b) {
[Link]("Order 1: int, double - " + a + ", " + b);
}
public void display(double a, int b) {
[Link]("Order 2: double, int - " + a + ", " + b);
}
public static void main(String[] args) {
MethodOverloading obj = new MethodOverloading();
[Link](10, 20.5);
[Link](30.7, 40);
}
}
OUTPUT
LAB REPORT 3: Write a Java program method overloading will be
implemented for Sequence of parameter will be different .
CODE
public class MethodOverloading {
public void display(int a, double b) {
[Link]("Sequence 1: int, double - " + a + ", " + b);
}
public void display(double a, int b) {
[Link]("Sequence 2: double, int - " + a + ", " + b);
}
public void display(double a, int b, int c) {
[Link]("Sequence 3: double, int, int - " + a + ", " + b + ", " + c);
}
public static void main(String[] args) {
MethodOverloading obj = new MethodOverloading();
// Calling the methods with parameters in different sequences
[Link](10, 20.5);
[Link](30.7, 40);
[Link](50.3, 60, 70);
}
}
OUTPUT
LAB REPORT 4: Write a Java program method
overloading will be implemented for multiple
main method.
CODE:
public class MainOverloading {
public static void main(String[] args) {
[Link]("Inside the first main method");
display("Hello from first main");
}
public static void main(int x) {
[Link]("Inside the second main method with argument: " + x);
display("Hello from second main");
}
public static void display(String message) {
[Link](message);
}
public static void main(double[] args) {
[Link]("Inside the third main method with double array");
display("Hello from third main");
}
public static void main(String arg1, String arg2) {
[Link]("Inside the fourth main method with two string arguments");
display("Hello from fourth main");
}
public static void main(String arg1, int arg2) {
[Link]("Inside the fifth main method with string and integer
arguments");
display("Hello from fifth main");
}
public static void main(int arg1, String arg2) {
[Link]("Inside the sixth main method with integer and string
arguments");
display("Hello from sixth main");
}
}
OUTPUT
LAB REPORT 5: Write a Java program method
overloading will be implemented for Data type
promotion.
CODE:
public class DataTypePromotion {
public void display(int a) {
[Link]("Integer method: " + a);
}
public void display(double a) {
[Link]("Double method: " + a);
}
public void display(float a) {
[Link]("Float method: " + a);
}
public static void main(String[] args) {
DataTypePromotion obj = new DataTypePromotion();
[Link](10);
[Link](20.5);
[Link](30.7f);
}
}
OUTPUT
LAB REPORT 6: Write a Java program method
overloading will be implemented for Data type
promotion.
CODE:
class Parent {
void display() {
[Link]("Parent's display method");
}
}
class Child extends Parent {
private void display() {
[Link]("Child's display method");
}
}
public class MethodOverrideDemo {
public static void main(String[] args) {
Parent parent = new Parent();
[Link](); // Calls Parent's display method
Child child = new Child();
}
}
OUTPUT
LAB REPORT 7: Write a Java program method
overloading will be implemented for Data type
promotion.
CODE:
class Parent {
final void display() {
[Link]("Parent's display method");
}
static void show() {
[Link]("Parent's show method");
}
}
class Child extends Parent {
}
}
public class MethodOverrideDemo {
public static void main(String[] args) {
Parent parent = new Parent();
[Link](); // Calls Parent's display method
[Link](); // Calls Parent's show method
Child child = new Child();
}
}
OUTPUT
LAB REPORT 7: Write a Java program for method
overriding by implementing super and this
Keyword.
CODE:
class Parent {
void display() {
[Link]("Parent's display method");
}
}
class Child extends Parent {
@Override
void display() {
[Link](); // Call superclass's display method
[Link]("Child's display method");
}
void callSuper() {
[Link]();
}
void callThis() {
[Link]();
}
}
public class MethodOverrideDemo {
public static void main(String[] args) {
Parent parent = new Parent();
[Link](); // Calls Parent's display method
Child child = new Child();
[Link]();
[Link]("--- Calling methods from Child object ---");
[Link]();
[Link]();
}
}
OUTPUT