Tuesday, July 30, 2024

Srtring MCQ

 In Java, which of the following best describes a string?

a) A primitive data type

b) A reference data type

c) A combination of characters

d) An array of characters


Which method in Java is used to obtain the length of a string?

a) length()

b) size()

c) count()

d) getSize()


Which method in Java is used to concatenate two strings?

a) append()

b) concat()

c) combine()

d) add()


Which method is used to compare two strings for equality in Java?

a) equals()

b) compareTo()

c) compare()

d) isEqual()


What is the purpose of the charAt() method in Java?

a) It returns the character at a specified index in a string.

b) It checks if a character exists in a string.

c) It modifies a character at a specified index in a string.

d) It returns the ASCII value of a character in a string.


Which method in Java is used to convert all characters in a string to lowercase?

a) toLower()

b) toLowerCase()

c) convertToLower()

d) caseLower()


Which method is used in Java to find the index of a specific character or substring within a string?

a) search()

b) find()

c) indexOf()

d) locate()


What is the purpose of the substring() method in Java?

a) It splits a string into multiple substrings.

b) It reverses a string.

c) It extracts a portion of a string.

d) It concatenates two strings.


Which method is used to remove leading and trailing white spaces from a string in Java?

a) removeSpaces()

b) trim()

c) strip()

d) clean()


What does the startsWith() method in Java do?

a) It checks if a string ends with a specific character or sequence.

b) It checks if a string starts with a specific character or sequence.

c) It checks if a string contains a specific character or sequence.

d) It checks if two strings are equal.


Answers:


c) A combination of characters

a) length()

b) concat()

a) equals()

a) It returns the character at a specified index in a string.

b) toLowerCase()

c) indexOf()

c) It extracts a portion of a string.

b) trim()

b) It checks if a string starts with a specific character or sequence.


MCQs on String and Methods in Java

What will be the output of the following code?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Hello";

        str.concat(" World");

        System.out.println(str);

    }

}

a) Hello World

b) Hello

c) World

d) Hello World


Answer: b) Hello

Explanation: The concat method returns a new string, but it does not modify the original string.


What will the following code print?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Java Programming";

        System.out.println(str.substring(5, 11));

    }

}

a) Program

b) Progra

c) Progra

d) Programming


Answer: b) Progra

Explanation: substring(5, 11) returns the substring from index 5 to 10 (the end index is exclusive).


What does the String.equalsIgnoreCase(String str) method do?


a) Compares two strings and returns true if they are equal, ignoring case differences.

b) Compares two strings and returns true if they are exactly equal.

c) Checks if one string contains another string, ignoring case differences.

d) Converts the string to lowercase.


Answer: a) Compares two strings and returns true if they are equal, ignoring case differences.

Explanation: equalsIgnoreCase compares two strings, ignoring their case.


What is the result of the following code?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Java";

        System.out.println(str.length());

    }

}

a) 3

b) 4

c) 5

d) Java


Answer: b) 4

Explanation: The length() method returns the number of characters in the string.


What will be the output of this code?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "   Hello   ";

        System.out.println(str.trim());

    }

}

a) Hello

b) Hello

c) Hello

d) Hello


Answer: a) Hello

Explanation: The trim() method removes leading and trailing whitespace.


What will the following code print?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Hello World";

        System.out.println(str.indexOf("World"));

    }

}

a) 6

b) 5

c) 0

d) 11


Answer: a) 6

Explanation: indexOf("World") returns the index of the first occurrence of "World".


What will be the output of the following code?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "hello";

        System.out.println(str.toUpperCase());

    }

}

a) HELLO

b) hello

c) Hello

d) HELLO


Answer: a) HELLO

Explanation: toUpperCase() converts all characters in the string to uppercase.


What is the result of this code?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Java Programming";

        System.out.println(str.replace('a', 'o'));

    }

}

a) Jovo Progroming

b) Jova Programming

c) Jovo Progromming

d) Jova Progromming


Answer: a) Jovo Progroming

Explanation: replace('a', 'o') replaces all occurrences of 'a' with 'o'.


What will be the output of this code?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Hello";

        System.out.println(str.charAt(2));

    }

}

a) H

b) e

c) l

d) o


Answer: c) l

Explanation: charAt(2) returns the character at index 2.


What will the following code print?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Java Programming";

        System.out.println(str.substring(5));

    }

}

a) Programming

b) Java Progr

c) Programming

d) Programming


Answer: a) Programming

Explanation: substring(5) returns the substring from index 5 to the end of the string.


What will the following code output?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Hello World";

        String newStr = str.concat("!");

        System.out.println(newStr);

    }

}

a) Hello World

b) Hello World!

c) Hello! World

d) Hello!World


Answer: b) Hello World!

Explanation: concat("!") adds ! to the end of the string.


What does the String.split(String regex) method do?


a) Splits the string into substrings based on the given regular expression.

b) Joins an array of strings into a single string using a delimiter.

c) Replaces all occurrences of a specified substring with another substring.

d) Converts the string to lowercase.


Answer: a) Splits the string into substrings based on the given regular expression.

Explanation: split divides the string based on the delimiter regex.


What will be the output of the following code?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Java Programming";

        String[] words = str.split(" ");

        System.out.println(words[1]);

    }

}

a) Java

b) Programming

c)

d) Error


Answer: b) Programming

Explanation: split(" ") separates the string into words, and words[1] is Programming.


What does the String.format(String format, Object... args) method do?


a) Formats a string based on the specified format and arguments.

b) Returns a string with leading and trailing spaces removed.

c) Converts the string to uppercase.

d) Replaces all occurrences of a specified character.


Answer: a) Formats a string based on the specified format and arguments.

Explanation: String.format creates a formatted string using the given format and arguments.


What will the following code print?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Hello";

        String newStr = str + " World";

        System.out.println(newStr);

    }

}

a) Hello World

b) Hello

c) World Hello

d) HelloWorld


Answer: a) Hello World

Explanation: Concatenation of str and " World" results in Hello World.



MCQs on String Methods in Java

What does the length() method of the String class return?


a) The number of words in the string.

b) The number of characters in the string.

c) The length of the longest word in the string.

d) The index of the last character.


Answer: b) The number of characters in the string.

Explanation: length() returns the total number of characters in the string.


What will be the output of the following code?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Hello World";

        System.out.println(str.toUpperCase());

    }

}

a) HELLO WORLD

b) hello world

c) Hello World

d) HELLO world


Answer: a) HELLO WORLD

Explanation: toUpperCase() converts all characters in the string to uppercase.


What will be the output of this code?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Java Programming";

        System.out.println(str.toLowerCase());

    }

}

a) JAVA PROGRAMMING

b) java programming

c) Java Programming

d) JaVa ProGrAmMiNg


Answer: b) java programming

Explanation: toLowerCase() converts all characters in the string to lowercase.


What does the charAt(int index) method do?


a) Returns the substring starting at the specified index.

b) Returns the character at the specified index.

c) Returns the index of the specified character.

d) Converts the character at the specified index to uppercase.


Answer: b) Returns the character at the specified index.

Explanation: charAt(index) returns the character at the given index.


What will be the result of the following code?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Java";

        System.out.println(str.indexOf('a'));

    }

}

a) 1

b) 2

c) 0

d) 3


Answer: b) 1

Explanation: indexOf('a') returns the index of the first occurrence of 'a', which is 1.


What does the lastIndexOf(String str) method return?


a) The index of the first occurrence of the string.

b) The index of the last occurrence of the string.

c) The length of the string.

d) The substring before the last occurrence.


Answer: b) The index of the last occurrence of the string.

Explanation: lastIndexOf returns the index of the last occurrence of the specified substring.


What will the following code output?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Programming";

        System.out.println(str.substring(3));

    }

}

a) Pro

b) gramming

c) gramming

d) Programming


Answer: b) gramming

Explanation: substring(3) returns the substring from index 3 to the end of the string.


What does substring(0, 2) do?


a) Returns the substring from index 0 to 2 (exclusive).

b) Returns the substring from index 2 to the end of the string.

c) Returns the substring from index 0 to 2 (inclusive).

d) Returns the substring from index 0 to 2 (exclusive).


Answer: a) Returns the substring from index 0 to 2 (exclusive).

Explanation: substring(0, 2) returns the substring starting from index 0 to 1.


What does the equals(Object obj) method do?


a) Compares two strings and returns true if they are equal, ignoring case.

b) Compares two strings and returns true if they are exactly equal.

c) Checks if the string contains another string.

d) Converts the string to lowercase.


Answer: b) Compares two strings and returns true if they are exactly equal.

Explanation: equals checks if two strings are exactly the same.


What will be the result of the following code?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str1 = "Hello";

        String str2 = "World";

        System.out.println(str1.concat(" ").concat(str2));

    }

}

a) HelloWorld

b) Hello World

c) Hello WorldWorld

d) Hello World HelloWorld


Answer: b) Hello World

Explanation: concat adds the given string at the end.


What does the contains(CharSequence sequence) method do?


a) Checks if the string starts with the specified sequence.

b) Checks if the string ends with the specified sequence.

c) Checks if the string contains the specified sequence.

d) Replaces all occurrences of the specified sequence.


Answer: c) Checks if the string contains the specified sequence.

Explanation: contains checks if the string contains the specified sequence of characters.


What will be the result of the following code?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Java Programming";

        System.out.println(str.startsWith("Java"));

    }

}

a) true

b) false

c) Java

d) Programming


Answer: a) true

Explanation: startsWith("Java") checks if the string starts with "Java".


What does the endsWith(String suffix) method check?


a) If the string starts with the specified suffix.

b) If the string ends with the specified suffix.

c) If the string contains the specified suffix.

d) If the string matches the specified suffix.


Answer: b) If the string ends with the specified suffix.

Explanation: endsWith checks if the string ends with the specified suffix.


What will be the output of this code?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "   Hello World   ";

        System.out.println(str.trim());

    }

}

a) Hello World

b) Hello World

c) Hello World

d) Hello World


Answer: a) Hello World

Explanation: trim() removes leading and trailing whitespace.


What does the toCharArray() method do?


a) Converts the string to an array of integers.

b) Converts the string to an array of characters.

c) Converts the string to a character sequence.

d) Converts each character in the string to uppercase.


Answer: b) Converts the string to an array of characters.

Explanation: toCharArray() returns a new character array containing the characters of the string.


What will be the result of this code?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "Java Programming";

        String replacedStr = str.replace('a', 'o');

        System.out.println(replacedStr);

    }

}

a) Jovo Progromming

b) Jova Programming

c) Jova Progromming

d) Jovo Programming


Answer: a) Jovo Progromming

Explanation: replace('a', 'o') replaces all occurrences of 'a' with 'o'.


What does the split(String regex) method do?


a) Splits the string based on the given regular expression.

b) Joins the array of strings into a single string using the specified delimiter.

c) Converts the string to uppercase.

d) Replaces all occurrences of the specified character.


Answer: a) Splits the string based on the given regular expression.

Explanation: split divides the string into substrings based on the provided delimiter.


What will the following code output?


java

Copy code

public class Main {

    public static void main(String[] args) {

        String str = "apple,banana,grape";

        String[] fruits = str.split(",");

        System.out.println(fruits.length);

    }

}

a) 2



Method Over loading

 

Method Over loading :

Definition: Writing multiple methods with the same name by passing different number of arguments/parameters.

Writing multiple methods with the same name by passing different data types.

Writing multiple methods with the same name by changing the order of parameters or by changing the position of data type.

ex1: //  Writing same method name by passing diff no of args  (or) parameters - MOL

package OOPSBasics;

public class MethodOveLoadingBasics1

{

               // Define M1 with no args/ parameters

               //  /// Instance Method -- (with out static k/w - if we define method - NonStatic Method )

               public void M1()

               {

                              System.out.println("calling  M1 with No arguments (or) No Parameters");

               }

               //            // Define M1 with 1 int arg/ parameter

               public void M1(int a)//   passing 1 arg/ para   // Instance Method or Non static Method

               {

                              System.out.println("calling  M1 with 1 argument (or)  Parameter");          

               }

               //            // Define M1 with 2 int args/ parameters              

               public void M1(int a, int b)//   2 parameters / args

               {

                              System.out.println("calling  M1 with 2 arguments (or)  Parameter");         

               }

               public static void main(String[] args) {

                              // Method Over loading:                            

                              // Create obj for class -MethodOveLoadingBasics1 with mObj1

                              MethodOveLoadingBasics1 mol =  new MethodOveLoadingBasics1();

                              //  call M1()

                              mol.M1();

                              // call M1()  - pass  10 value        

                              mol.M1(10);

                              // HW   Call M1  with 2 args

               }

}

o/p:

calling  M1 with No arguments (or) No Parameters

calling  M1 with 1 argument (or)  Parameter

HW Define M2()  with 1 float arg   and Define M2() with 2 float args and Define M2() with 3 float args, call  all the methods one by one ?

HW  Define M3() with 1 char arg, 2 char args, 3 char args, call  all the methods one by one ?

HW  Define M4() with 1 String arg, 2 String args, 3 String args, call  all the methods one by one ?

//2. Writing the same method   by  passing diff data types           

package OOPSBasics;

public class MethodOveLoadingBasics2

{

               // Define M1 with  1 int arg

               public void M1(int a)// M1 with 1 args / Parameter

               {

                              System.out.println("M1 Method with 1 int arg");

               }             

                  // Define M1 with  1 float arg

               public void M1(float a)   // Method with 1 arg  of type float

               {

                              System.out.println("M1 Method with 1 arg  of type float");

               }

                 // Define M1 with  1 char arg

               public void M1(char ch) // 1 arg  of char type

               {

                              System.out.println("M1 Method with 1 arg  of char type");           

               }

                             

               public static void main(String[] args)

               {

                              //create obj for class- MethodOveLoadingBasics2

                              MethodOveLoadingBasics2 mol2 =  new MethodOveLoadingBasics2();

                             

                              // call M1() with 1 int value

                              mol2.M1(10);

                             

                              // Call M1() with float val

                              mol2.M1(2.45f);

                             

                              // HW Call M1() with char val

               }

}

o.p:

M1 Method with 1 int arg

M1 Method with 1 arg  of type float

              

HW Define M2 () with 1 String arg and Define M2() with 1 boolean arg and call all methods ?

//3. Writing the same method   by changing the position of data type

package OOPSBasics;

public class MethodOveLoadingBasics3

{

               // Define M1() with 1 int arg and 1 char arg

               public void M1(int a, char ch)

               {

                              System.out.println("Method -2 args 1st arg is of int, 2nd arg is of type char ");

               }

// define M1() with 1 char arg and 1 int arg

               public void M1(char ch, int a) // // 2 args, 1st arg is of char, 2nd arg is of type int

               {

                              System.out.println("Method -2 args 1st arg is of char, 2nd arg is of type int ");

               }

                             

               public static void main(String[] args)

               {

                              //create obj for class-

                             

                              //HW  call all the 2  methods

               }

}

 

ex3:Define  add()  with MOL

package OOPSBasics;

public class MethodOveLoadingBasics2

{

               // Define add() with no args -     

                              public void add()//  non static or instance Method

                              {

                                             System.out.println("Calling add () with no args");

                              }             

                              // Define add() with 1 int arg

                              public void add(int a)

                              {          //     10  . s0 a =10

                                             System.out.println("Calling add () with 1 args");

                              }

                              //            // Define add() with 2  int args

                              public void add(int a, int b)

                              {              //              10      20

                                             int res = a+b;

                                             //        10 + 20

                                             //          30

                                             //  res = 30

                                             System.out.println("Calling add () with 2 args. Res= "+ res);

                                             //                                                      30

                              }

                              //            // Define add() with 3  int args

                              public void add(int a, int b, int c)

                              {              //              10     20      30

                                             int res = a+b +c;

                                             //        10 + 20 + 30

                                             //           60

                                             //    res = 60

                                             System.out.println("Calling add () with 3 args. Res= "+ res);

                                             //                                                       60

                              }                            

                              public static void main(String[] args) {

                                                                          

                                             // call non static or instance method -- 1st we have to create obj  for class- MethodOveLoadingBasics2

                                             MethodOveLoadingBasics2 mol2 = new MethodOveLoadingBasics2();

                                              

                                             // call add() with 1 args

                                             mol2.add(10);

                                             // call add() with 2 args

                                             mol2.add(10,20);

                                             // call add() with 3 args

                                             mol2.add(10, 20, 30);

                                            

                              }

               }

o/p:

Calling add () with 1 args

Calling add () with 2 args. Res= 30

Calling add () with 3 args. Res= 60

HW  WAP to over load Multiplication method with 2 int number, 3  int numbers and call all methods?

   mul(2,3)

   mul(2,3,4)

HW  WAP to over load Multiplication method with 2 float numbers, 3 float numbers and call all methods??

    mul(1.0f,2.0,3.0f);

Ex4: Duplicate Methods are Not Allowed with the Same Signature

  • Definition: In Java, a method's signature is defined by its name and the parameter types. When two methods have the same name and parameter types, they are considered to have the same signature.
  • Restriction: Java does not allow two methods with the same signature in the same class because the compiler cannot differentiate between them based on the method name and parameter types alone.

 

package OOPSBasics;

public class MethodOveLoadingBasics1

{

               // Define M1() // No args / no Parameters

                                             public void M1()

                                             {

                                                            System.out.println("M1 Method with no args");

                                             }

                                            

                                             // can we write same method and same data type? No

                              // define method M1() // no args

//                                          public void M1() // Error Duplicate method M1() in type MethodOveLoadingBasics1

//                                          {

//                                                         System.out.println("M1 Method with no args");

//                                          }

                              // No args / no Parameters  //CE: Duplicate method M1() in type MOLBasics1

                                             // Define M1() with 1 int arg

                                             public void M1(int a) //// M1()  with 1 arg / parameter

                                             {

                                                            System.out.println("M1 Method with 1 int arg");

                                             }

                                                           

                                             // Define above method again

//                                          public void M1(int a) //// Error  M1()  with 1 arg / parameter

//                                          {

//                                                         System.out.println("M1 Method with 1 int arg");

//                                          }

                                                                                         

                                            

                              public static void main(String[] args) {

                                                            System.out.println("in main ");

                                                           

                                                                          

                              }

               }

FAQ What is Method Over loading ?

**********************************************

**********************************************

Write the o/p for below program?

package OOPSBasics;

public class MethodOveLoadingBasics3

{

               static void M1(char ch, int a) // 2 args 1st arg is of char, 2nd arg is of type int

               {  //              'A'      10   so ch = 'A' , a = 10

                              int res=  ch + a;

                              //         'A'  + 10

                              //         65 + 10  =

                              //          75

                              //   res=   75

                              System.out.println("res="+ res);

                                             //                       75

                              System.out.println("Method -2 args 1st arg is of char, 2nd arg is of type int ");

               }

              

               static void M1(int a, char ch)// 2 args

               {  //               2      'A' so a= 2   , ch ='A'

                              int res=  ch + a;

                              //        'A' + 2 

                              //         65 + 2

                              //        67

                              //  res=  67

                              System.out.println("res="+ res);

                                             //              67

                              System.out.println("Method -2 args 1st arg is of int, 2nd arg is of type char ");

               }

               public static void main(String[] args)  // main() -static  method

               {

                              System.out.println("in main ");

                              // call M1(char ch, int a)

                              M1('A',10);

                              // call static void M1(int a, char ch)/                                      

                              M1(2,'A');

               }

}

o/p:

in main

res=75

Method -2 args 1st arg is of char, 2nd arg is of type int

res=67

Method -2 args 1st arg is of int, 2nd arg is of type char

**************************************************

               2-Apr-2024

**************************************************

Write o/p for below program?

--------------------------------------

package OOPSBasics;

public class MOLBasics3

{

               static void M1(String s, int a)// static method

               {              //               Ram     10   so s ="Ram"    and a =10

//                           int res=  s + a; // errorType mismatch: cannot convert from String to int

                              //        "Ram" + 10             

                              //          "Ram10"         o/p is in the form of String .

                              //so left side, we must declare string variable but not int var

                             

                              String res1=  s+ a;

                              //           "Ram" +  10 --> concatenation - joining

                              //             "Ram10"

                              //       res1 = "Ram10"     

                              System.out.println("res="+ res1);

                              //                           Ram10

               }

               public static void main(String[] args)

               {

                              System.out.println("in main ");

                             

                              M1("Ram",10);

               }

}

o/p:

in main

res=Ram10

FAQ Can we over load main()?

package OOPSBasics;

public class MethodOveLoadingBasics2

{

              

               // FAQ Can we over load main()? yes

              

                              void main() //  static or non static method or Instance

                              {

                                             System.out.println("Calling main() - o args");

                              }

                             

                              void main(int a) //  passing 1 arg

                              {

                                             System.out.println("Calling main() - 1 args- int");

                              }                            

                              void main(char a)

                              {

                                             System.out.println("Calling main() - 1 args - char."+ a);

                              }

                             

                              public static void main(String [] args) {

                                             // Create obj for class -MethodOveLoadingBasics2

                                             MethodOveLoadingBasics2  mol2 = new MethodOveLoadingBasics2 ();                                                           

                                             // call main() with no args

                                             mol2.main();

                                                            // call main() with 1 int  args

                                             mol2.main(10);

                                                            // call main() with 1 char  args

                                             mol2.main('A');

                                             // call main() with String "Ramu" ?

//                                          mol2.main("Ramu");// Error        // The method main(int) in the type MethodOveLoadingBasics2 is not applicable for the arguments (String)

                                             //  error as we did not define / write any method with String args/ parameter

                                            

                                             // call main() with double value 10.3

//                                          mol2.main(2.45f);// error

//                                          mol2.main(2.45d);// error

               //  error as we dont have main( double d) or float arg

                                            

                                             String sarr [] = {"Ram", "sita","Lakshman"};

                                             mol2.main(sarr);// Exception in thread "main" java.lang.StackOverflowError

                                            

                              }

               }

Note:

press Ctrl + A,  and  Ctrl + I --   Indentation (or) proper allignment of code

ex:  if we dont have main()  with string array , Can we run the program?

package OOPSBasics;

public class MethodOveLoadingBasics2

{

               //            public static void main(String[] args) // JVM always looks in current class main() which starts with public

               //  static void   and method with args  String array only -- Then JVM  runs proagram

               //   if main (String [] arr)  is not there,  JVM will not run the program

               //  We cannot see run as >  Java application option

               public static void main(String[] sarr)

//                           public static void main(int[] iArr)

               //            public static void main(String s)

               { //  

                              System.out.println("in Main ");

               }

}

Can we have 2 main(String args) ?

No.

package OOPSBasics;

public class MethodOveLoadingBasics2

{

               public static void main(String[] sarr) // Errro :Duplicate method main(String[]) in type MethodOveLoadingBasics2

               {

                             

              

               }

               public static void main(String[] sarr)

               { //  

                              System.out.println("in Main ");

               }

}

Can we pass diff array name in main()  should I pass array name i.e args in main()?

we can pass any diff array name - other than args i.e sarr, arr

 

package OOPsBasics1;

public class MethodOveLoadingBasics2 {

               // Note :  we dont need to pass args only  -- we cann give / pass differ array name i.e arr,  sArr

//            public static void main(String[] args)  //   args  - array variable anme -

               public static void main(String[] arr)

               {

                              //                           m2.main("Ramu");

                              // The method main(int) in the type MethodOveLoadingBasics2 is not applicable for the arguments (String)

                              //  error as we did not define / write any method with String args/ parameter

                              //                           m2.main(10.3);//  error as we dont main( double d)

               }

}

Note:

//            int main(int a) // changing return type of method --  does not come under MOL

//            {

//                           System.out.println("Calling main() - 1 args- int");

//            }

 In Java, changing only the return type of a method while keeping the same method name and parameter types does not constitute method overloading.

Method overloading requires methods to have different parameter lists, either in the number of parameters, their types, or both. The return type alone cannot distinguish methods because the method signature does not include the return type. Thus, having two methods with the same name and parameter list but different return types will result in a compilation error.

git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...