Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
17 views

Advance Programming

Uploaded by

sohel8154754
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Advance Programming

Uploaded by

sohel8154754
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

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) {


System.out.println("One parameter method: " + a);
}
public void display(int a, int b) {
System.out.println("Two parameters method: " + a + ", " + b);
}
public void display(int a, int b, int c) {
System.out.println("Three parameters method: " + a + ", " + b + ", " + c);
}

public static void main(String[] args) {


MethodOverloading obj = new MethodOverloading();
obj.display(10);
obj.display(20, 30);
obj.display(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) {


System.out.println("Order 1: int, double - " + a + ", " + b);
}

public void display(double a, int b) {


System.out.println("Order 2: double, int - " + a + ", " + b);
}

public static void main(String[] args) {


MethodOverloading obj = new MethodOverloading();

obj.display(10, 20.5);
obj.display(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) {


System.out.println("Sequence 1: int, double - " + a + ", " + b);
}

public void display(double a, int b) {


System.out.println("Sequence 2: double, int - " + a + ", " + b);
}

public void display(double a, int b, int c) {


System.out.println("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


obj.display(10, 20.5);
obj.display(30.7, 40);
obj.display(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) {


System.out.println("Inside the first main method");
display("Hello from first main");
}

public static void main(int x) {


System.out.println("Inside the second main method with argument: " + x);
display("Hello from second main");
}

public static void display(String message) {


System.out.println(message);
}
public static void main(double[] args) {
System.out.println("Inside the third main method with double array");
display("Hello from third main");
}

public static void main(String arg1, String arg2) {


System.out.println("Inside the fourth main method with two string arguments");
display("Hello from fourth main");
}

public static void main(String arg1, int arg2) {


System.out.println("Inside the fifth main method with string and integer
arguments");
display("Hello from fifth main");
}

public static void main(int arg1, String arg2) {


System.out.println("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) {
System.out.println("Integer method: " + a);
}
public void display(double a) {
System.out.println("Double method: " + a);
}
public void display(float a) {
System.out.println("Float method: " + a);
}

public static void main(String[] args) {


DataTypePromotion obj = new DataTypePromotion();

obj.display(10);
obj.display(20.5);
obj.display(30.7f);
}
}

OUTPUT
LAB REPORT 6: Write a Java program method

overloading will be implemented for Data type

promotion.

CODE:
class Parent {

void display() {
System.out.println("Parent's display method");
}
}

class Child extends Parent {

private void display() {


System.out.println("Child's display method");
}
}

public class MethodOverrideDemo {


public static void main(String[] args) {
Parent parent = new Parent();
parent.display(); // 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() {


System.out.println("Parent's display method");
}

static void show() {


System.out.println("Parent's show method");
}
}

class Child extends Parent {


}
}

public class MethodOverrideDemo {


public static void main(String[] args) {
Parent parent = new Parent();
parent.display(); // Calls Parent's display method
parent.show(); // 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() {
System.out.println("Parent's display method");
}
}

class Child extends Parent {


@Override
void display() {
super.display(); // Call superclass's display method
System.out.println("Child's display method");
}

void callSuper() {
super.display();
}

void callThis() {
this.display();
}
}
public class MethodOverrideDemo {
public static void main(String[] args) {
Parent parent = new Parent();
parent.display(); // Calls Parent's display method

Child child = new Child();


child.display();
System.out.println("--- Calling methods from Child object ---");
child.callSuper();
child.callThis();
}
}

OUTPUT

You might also like