Access Millions of academic & study documents

3 3 Given the following code public class Test1 {public Object m

Content type
User Generated
Showing Page:
1/6
3.3 Given the following code.
public class Test1 {
public Object max(Object o1, Object o2) { if
((Comparable)o1.compareTo(o2) >= 0) { return o1;
} else { return o2;
}
}
}
a. The program has a syntax error because Test1 does not
have a main method.
b. The program has a syntax error because o1 is an Object
instance and it does not have the compareTo method.
c. The program has a syntax error because you cannot
cast an Object instance o1 into
Comparable.
d. The program would compile if
((Comparable)o1.compareTo(o2) >= 0) is replaced by
(((Comparable)o1).compareTo(o2) >= 0).
e. b and d are both correct.
3.5
Analyze the following code. class Test {
public static void main(String[] args) {
Object x = new Integer(2);
System.out.println(x.toString());
}
}
a. The program has syntax errors because an Integer
object is assigned to x.
b. When x.toString() is invoked, the toString() method in
the Object class is used.
c. When x.toString() is invoked, the toString() method in
the Integer class is used.
d. None of the above.

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/6
3.8- Suppose List<String> list = new ArrayList<>().
Which of the following operations are correct?
A. list.add(new Integer(100));
list.add(new ArrayList());
list.add(\"Red\");
list.add(new java.util.Date());
3.9
Which of the following is correct to sort the elements in a
list lst?
A.new LinkedList(new String[]{\"red\", \"green\", \"blue\"})
B.lst.sort()
C.Arrays.sort(lst)
D.Collections.sort(lst)
3.12 Which 2 are valid declarations in an interface?
a.static long shanks = 343;
b.protected static short timer = 23;
c.private short hop = 12;
d.final int stuffit(short hop);
e.public void doMore(long bow);
f.static void doMore(double trouble);
3.13 Given the following code: public class Test{ public
static void throwEx(){ System.out.println(throwex);
throw new RuntimeException();
}
3.12
public static void main(String[] args){ try{
System.out.print(try); throwEx();
} catch (Exception e) {
System.out.print(catch);
} finally {
System.out.println(finally);
}
System.out.println(done);
}
}

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/6

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 6 pages?
Access Now
Unformatted Attachment Preview
3.3 Given the following code. public class Test1 { public Object max(Object o1, Object o2) { ((Comparable)o1.compareTo(o2) >= 0) { } else { return o2; } } } if return o1; a. The program has a syntax error because Test1 does not have a main method. b. The program has a syntax error because o1 is an Object instance and it does not have the compareTo method. c. The program has a syntax error because you cannot cast an Object instance o1 into Comparable. d. The program would compile if ((Comparable)o1.compareTo(o2) >= 0) is replaced by (((Comparable)o1).compareTo(o2) >= 0). e. b and d are both correct. 3.5 Analyze the following code. class Test { public static void main(String[] args) { Object x = new Integer(2); System.out.println(x.toString()); } } a. The program has syntax errors because an Integer object is assigned to x. b. When x.toString() is invoked, the toString() method in the Object class is used. c. When x.toString() is invoked, the toString() method in the Integer class is used. d. None of the above. 3.8- Suppose List list = new ArrayList(). Which of the following operations are correct? A. list.add(new Integer(100)); list.add(new ArrayList()); list.add(\"Red\"); list.add(new java.util.Date()); 3.9 Which of the following is correct to sort the elements in a list lst? A.new LinkedList(new String[]{\"red\", \"green\", \"blue\"}) B.lst.sort() C.Arrays.sort(lst) D.Collections.sort(lst) 3.12 Which 2 are valid declarations in an in terface? a.static long shan ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4