Constructors & Lang
Classes Answers
a ) Cat (double x, double y ) { /* */ }
b) Cat( int j, int k ) { /* */ }
c) Cat( ) { /* */ }
d) Cat ( float u, int p ) { /* */
}
( a )
3) What will the following print out? Select the correct answer.
String x1 = "X";
String x2 = "X";
if (x1.equals(x2))
System.out.println( "Positive")
else
System.out.println("Negative")
a ) Positive
b ) Negative
( a )
// A deep comparison is executed where the same value is stored in both
// strings
the if statement evaluates to true and 'Positive' is printed
4) What will the following print out? Select the correct answer.
String x1 = "X";
String x2 = "X";
if (x1==x2)
System.out.println( "Positive")
else
System.out.println("Negative")
a )
b)
( a )
// Positive is printed because the shallow comparison compares
addresses
and in
// this case
the addresses are for the same string literal in the string literal pool
3) One of the following is not a valid wrapper class. Which is it?
a) Float
b) Int
c) Double
d) Long
( b )
// Not in long
form
4) Which of the following statements is not correct?
a) The math class itself is final so can only
be
extended once
b) Math's constructor is private so it cannot be
instantiated.
c) Math methods and constants are static
d) Math methods are only accessible through the
Math
class name ( a )
// The
math class is final so cannot be extended at all
5) Math.floor(44.4) returns
a) 45
b) 45.0
c) 44
d) 44.0
( c )
6) Which of the following is not in the java lang package
a) Vector
b) Boolean
c) Math
d)
String
( a )
// Vector needs
to be imported
7 ) With respect to Vector class, which of the following statements is not correct?
a) The number of objects added may exceed the capacity.