?
Solved

add method

Posted on 2011-04-26
4
Medium Priority
?
258 Views
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

http://www.jchq.net/certkey/0803certkey.htm

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.
0
Comment
Question by:gudii9
  • 2
4 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 668 total points
ID: 35471949
There is no add method in Integer class
You need to get intValue() - primitive type int
and then add two numbers

0
 
LVL 92

Assisted Solution

by:objects
objects earned 668 total points
ID: 35471969
Integer and other primitive wrapper classes are immutable (the same as String)
you cannot change the value
0
 
LVL 16

Assisted Solution

by:imladris
imladris earned 664 total points
ID: 35476618
The question is, which of the lines is valid code. The answer is that all of them are except number 3:

System.out.println(Integer.add(2,2));

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.
0
 
LVL 16

Expert Comment

by:imladris
ID: 35707109
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

840 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