Video 32(ch7)

Yash
0

 



Program:-

public class MethodOverloadingV32 {
    /*Here Static keyword is use to associate a method of a given class with the class rather than the object.
     * and the void keyword is used because the following method do not have any written type*/
    static void TellJoke(){
        System.out.println("Why do cows wear bells \nas their horns don't work");
    }
        static int change(int a){
        a = 98;
        return a;
    }
    static void change2(int [] arr){
        arr[0] = 98;
    }

    //Method Overloading.
    static void foo(){
        System.out.println("Good morning bro!");
    }
    static void foo(int a){
        System.out.println("Good morning" + a +"bro!");
    }
    static void foo(int a, int b){
        System.out.println("Good morning" + a +"bro!");
        System.out.println("Good morning"+ b +"bro!");

    }
        public static void main(String[] args) {
            TellJoke();
            System.out.println();
            int x = 45;
            change(x);
            System.out.println("The value of x after running change is: " + change(x) + "\n");
        /*here we assign the x = 45 to the 'change' method in the positions of int a and in this method
        the value 98 is assign to the "a" and so as the "x" becomes "a" after assignment the a is also becomes 98*/
            /*as happen above the value of marks[0] become 98*/
            int [] marks = {52, 73, 77, 89, 98, 94};
            change2(marks);
            System.out.println("array element at zero position after the running the change is: " + marks[0]);
            System.out.println("and the resultant array is");
            for(int a: marks){
                System.out.print(a + " ");
            }
            System.out.println();
            System.out.println();

            foo();
            foo(3000);
            foo(3000,4000);
        }
}


Post a Comment

0 Comments
Post a Comment (0)
To Top