Java Reference
In-Depth Information
14. 3, 4,
3.0, 3.0,
4.0, and 4.0
15. roundedAnswer = ( int )Math.round(answer);
16. long . Since one argument is of type long , the int argument is automatically type
cast to long .
17.
They are all legal.
18.
An object of the class Double ; the assignment is equivalent to
Double price = new Double(1.99);
19.
A value of the primitive type int; the assignment is equivalent to
int count = ( new Integer(12)).intValue();
20. Objects are Not equal.
21. Double.toString(result )
22. Double.parseDouble(stringForm)
23. Double.parseDouble(stringForm.trim())
24. System.out.println("Largest long is " + Long.MAX_VALUE +
" Smallest long is " + Long.MIN_VALUE);
25. Character zeeObject = new Character('Z');
26.
No, none of the wrapper classes discussed in this chapter have no-argument
constructors.
27.
A reference type is a type whose variables contain references, that is, memory
addresses. Class types are reference types. Primitive types are not reference types.
28.
When comparing two objects of a class type, you should use the method equals .
29.
When comparing two objects of a primitive type, you should you use == .
30.
Yes, a method with an argument of a class type can change the values of the
instance variables in the object named by the argument.
31.
No, a method cannot change the value of an int variable given as an argument
to the method.
32.
The variable anObject names no object and so the invocation of the set method
is an error. One way to fix things is as follows:
ToyClass anObject = new ToyClass();
anObject.set("Josephine", 42);
33.
The constant null can be assigned to a variable of any class type. It does not
really have a type, but you can think of its type as being the type of a memory
address. You can also think of null as being of every class type.
Search WWH ::




Custom Search