PRO192 Chap 4 Questions and Answers 2024
Which of the following statements is correct? (Choose one.)
A. Only primitives are converted automatically; to change the type of an object reference, you
have to do a cast.
B. Only object references are converted automatically; to change the type of ...
Which of the following statements is correct? (Choose one.)
A. Only primitives are converted automatically; to change the type of an object
reference, you
have to do a cast.
B. Only object references are converted automatically; to change the type of a primitive,
you
have to do a cast.
C. Arithmetic promotion of object references requires explicit casting.
D. Both primitives and object references can be both converted and cast.
E. Casting of numeric types may require a runtime check. ** Answ** d
Which one line in the following code will not compile?
1. byte b = 5;
2. char c = '5';
3. short s = 55;
4. int i = 555;
5. float f = 555.5f;
6. b = s;
7. i = c;
8. if (f > b)
9. f = i;
A. Line 1
B. Line 2
C. Line 3
D. Line 4
E. Line 5
F. Line 6
G. Line 7
H. Line 8
I. Line 9 ** Answ** f
Will the following code compile?
1. byte b = 2;
2. byte b1 = 3;
3. b = b * b1;
A. Yes
B. No ** Answ** b
In the following code, what are the possible types for variable result? (Choose the most
complete
true answer.)
, 1. byte b = 11;
2. short s = 13;
3. result = b * ++s;
A. byte, short, int, long, float, double
B. boolean, byte, short, char, int, long, float, double
C. byte, short, char, int, long, float, double
D. byte, short, char
E. int, long, float, double ** Answ** e
Consider the following class:
1. class Cruncher {
2. void crunch(int i) {
3. System.out.println("int version");
4. }
5. void crunch(String s) {
6. System.out.println("String version");
7. }
8.
9. public static void main(String args[]) {
10. Cruncher crun = new Cruncher();
11. char ch = 'p';
12. crun.crunch(ch);
13. }
14. }
Which of the following statements is true? (Choose one.)
A. Line 5 will not compile, because void methods cannot be overridden.
B. Line 12 will not compile, because no version of crunch() takes a char argument.
C. The code will compile but will throw an exception at line 12.
D. The code will compile and produce the following output: int version.
E. The code will compile and produce the following output: String version. ** Answ**
d
Which of the following statements is true? (Choose one.)
A. Object references can be converted in assignments but not in method calls.
B. Object references can be converted in method calls but not in assignments.
C. Object references can be converted in both method calls and assignments, but the
rules
governing these conversions are very different.
D. Object references can be converted in both method calls and assignments, and the
rules
governing these conversions are identical.
E. Object references can never be converted. ** Answ** d
Consider the following code. Which line will not compile?
1. Object ob = new Object();
2. String[] stringarr = new String[50];
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller smartchoices. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $9.19. You're not tied to anything after your purchase.