Menu
Topics Index
...
`

Good


If you need explanation Read this topic

If you need Answer Take test on this topic

Good
What will be the output of the following program?
public class Good {
    public static void main(String args[]) {
        int bp = 175;
        String s = Integer.toHexString(bp);
        String str = toHexString(bp);
        System.out.println(s);
        System.out.print(str);
    }
    static public String toHexString(int bp) {
        return "good";
    }
}

A. 175
good
B. af
good
C. good
175
D. good
good
E. Compilation Error or Runtime Error
Topic: Unknown

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans B here we have the Wrapper class Concept..here we have an int variable with the value 175..next we are calling the toHexString() method which is present in the Integer class which is used to convert given decimal number into hexadecimal number and 175 equivalent Hexa num is AF and next we are calling the toHexString() so here it will invoke the method in the Good class and returns as good..here we can call static methods directly from a static method..

Posted by Uday Kumar    2015-01-02 12:10:36


B is the answer the variable 175 is converted using hexadecimal to af

Posted by Asad Ahmed    2015-01-03 03:42:43


ans b.toHexString() This method returns the string representation of the unsigned integer value represented by the argument in hexadecimal (base 16).initially bp assigned with175.integer. tohexString () returns hex value of givn int number so af get printed.toHexString(int) invokes static toHexString so it returns "good".

Posted by NagaRaj Nataraj    2015-01-03 07:37:45


ANS IS B

Here toHexString() is used.One method of Integer class is used which accepts integer variable bp and convert it into Hexadecimal String.

175 in Decimal=af in Hexadecimal

--When s is printed then "af" will get printed and cursor will go to next line.

--One toHexString() method is defined in Good class which accepts integer variable and return "good" String.when "str" is printed,"good" will get printed.

Posted by Mânïshå Mùlchåndânï    2015-01-03 10:50:37


ans is b

Posted by Kambam Divya    2015-01-06 04:56:14


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', NagaRaj Nataraj,  for 'Best Comment' and Mânïshå Mùlchåndânï for the 'Popular Comment'. The 'lucky liker' is Sai Ram. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-01-06 05:03:56


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', NagaRaj Nataraj,  for 'Best Comment' and Mânïshå Mùlchåndânï for the 'Popular Comment'. The 'lucky liker' is Sai Ram. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-01-06 05:03:57


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', NagaRaj Nataraj,  for 'Best Comment' and Mânïshå Mùlchåndânï for the 'Popular Comment'. The 'lucky liker' is Sai Ram. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-01-06 05:03:59


© meritcampus 2019

All Rights Reserved.

Open In App