Access Millions of academic & study documents

2Which of the following is poor designA A method must be invok

Content type
User Generated
Showing Page:
1/12
2
Which of the following is poor design?
A. A method must be invoked after/before invoking another
method in the same class.
B. A data field is derived from other data fields in the same
class.
C. A method is an instance method, but it does not
reference
any instance data fields or invoke
instance methods.
D. A parameter is passed from a constructor to initialize a
static data field.
3
The java.lang.Number and its subclasses are introduced in
Chapter 11. Analyze the following
code.
Number numberRe
f = new Integer(0);
Double doubleRef = (Double)numberRef;
A. A runtime class casting exception occurs, since
numberRef is not an instance of Double.
B. The program runs fine, since Integer is a subclass of
Double.
C. You can convert an int to doubl
e, so you can cast an Integer instance to a Double
instance.
D. There is no such class named Integer. You should use
the class Int.
E. The compiler detects that numberRef is not an instance
of Double.
4
Which of the following statements are correct?
A. Double i = 4.5;
B. Integer i = 4.5;
C. Number i = 4.5;

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/12
D. Object i = 4.5;
5
Which of the following statements are true?
A. If you compile an interface without errors, but with
warnings, a .class file is created for the
interface.
B. If you compi
le a class with errors, a .class file is created for the class.
C. If you compile an interface without errors, a .class file is
created for the interface.
D. If you compile a class without errors but with warnings,
a .class file is created.
6
Analyze t
he following code.
public
class
Test
{
public static void main(String[] args) {
java.util.Date x = new java.util.Date();
java.util.Date y = x.clone();
System.out.println(x = y);
}
}
A. x = y in System.out.println(x = y) causes a compile
error because you cannot have an
assignment statement inside a statement.
B. A java.util.Date object is not cloneable.
C. The program has a compile error because the return
type of the clone() method is
java.lang.Object.
D.
x = y in System.out.println(x = y) causes a runtime error
because you cannot have an
assignment statement inside a statement.

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/12

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 12 pages?
Access Now
Unformatted Attachment Preview
2 Which of the following is poor design? A. A method must be invoked after/before invoking another method in the same class. B. A data field is derived from other data fields in the same class. C. A method is an instance method, but it does not reference any instance data fields or invoke instance methods. D. A parameter is passed from a constructor to initialize a static data field. 3 The java.lang.Number and its subclasses are introduced in Chapter 11. Analyze the following code. Number numberRe f = new Integer(0); Double doubleRef = (Double)numberRef; A. A runtime class casting exception occurs, since numberRef is not an instance of Double. B. The program runs fine, since Integer is a subclass of Double. C. You can convert an int to doubl e, so you can cast an Integer instance to a Double instance. D. There is no such class named Integer. You should use the class Int. E. The compiler detects that numberRef is not an instance of Double. 4 Which of the following statements are correct? A. Double i = 4.5; B. Integer i = 4.5; C. Number i = 4.5; D. Object i = 4.5; 5 Which of the following statements are true? A. If you compile an interface without errors, but with warnings, a .class file is created for the interface. B. If you compi le a class with errors, a .class file is created for the class. C. If you compile an interface without errors, a .class file is created for the interface. D. If you compile a class without errors but with warnings, a .class file is created. 6 Anal ...
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