What is the result?

Given:


What is the result?
A. Good Day!
Good Luck!
B. Good Day!
Good Day!
C. Good Luck!
Good Day!
D. Good Luck!
Good Luck!
E. Compilation fails

Download Printable PDF. VALID exam to help you PASS.

0 thoughts on “What is the result?

  1. Option A.

    public class Test {

    public static String doMsg(char x) {
    return “Good Day!”;
    }

    public static String doMsg(int y) {
    return “Good Luck!”;
    }

    public static void main(String[] args) {

    char x = 8;
    int z = ‘8’;

    System.out.println(doMsg(x));
    System.out.print(doMsg(z));
    }
    }

    Output:
    Good Day!
    Good Luck!

    Explanation:
    The variable “x” is assigned the ASCII sign of code 8 (“\b” or “BS” – non printable! sign) and enters the method doMsg(char x).
    The variable “z” is assigned the ASCII code of the sign “8” (which is 56) and enters the method doMsg(int y).
    NOTE: this example wouln’t compile, if “z” was assigned a two digit number (no ASCII code, not char type).

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.