add method

Posted on 2011-04-26
Last Modified: 2012-08-14
>>Which of the following is valid code?

1) System.out.println(Integer.toBinaryString(4));
2) System.out.println(Integer.toOctalString(4));
3) System.out.println(Integer.add(2,2));
4) Float[] ar = new Float[] { new Float(1.0), new Float(2.1)};

Answer to Question 5

1) System.out.println(Integer.toBinaryString(4));
2) System.out.println(Integer.toOctalString(4));
4) Float[] ar = new Float[] { new Float(1.0), new Float(2.1)};

The wrapper classes contain no methods for manipulating the contents as if they were primitives, thus add method in option 3 does not exist. If you want to do that you need to extract the primitive values represented and work on them.

i was going through above question from following link

It is not clear to me.

There is no add method on Integer class.

Any ideas, resources, links, sample code highly appreciated. thanks in advance.
Question by:gudii9
    LVL 47

    Accepted Solution

    There is no add method in Integer class
    You need to get intValue() - primitive type int
    and then add two numbers

    LVL 92

    Assisted Solution

    Integer and other primitive wrapper classes are immutable (the same as String)
    you cannot change the value
    LVL 16

    Assisted Solution

    The question is, which of the lines is valid code. The answer is that all of them are except number 3:


    This is not valid code. The Integer class does *not* have an "add" method, and therefore this code will not compile. If you wanted to add to integers you would have to do it differently.
    LVL 16

    Expert Comment

    Did this answer your question?

    If so it is now time to grade and close the question.

    If not, perhaps a clarifying question would help.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now