exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 4 discussion

Actual exam question from Oracle's 1z0-808
Question #: 4
Topic #: 1
[All 1z0-808 Questions]

Given the code fragment:

What is the result?

  • A. Sum is 600
  • B. Compilation fails at line n1.
  • C. Compilation fails at line n2.
  • D. A ClassCastException is thrown at line n1.
  • E. A ClassCastException is thrown at line n2.
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
theCloudCTO
Highly Voted 5 years ago
C. This is a casting issue but the code fails to compile so the answer is c. The ClassCastException is a runtime exception where you're trying to cast an object to a different object type, but here the code fails to compile because you cannot cast a long to a string.
upvoted 10 times
...
rasifer
Highly Voted 5 years, 8 months ago
Sorry, answer is C....tested..
upvoted 6 times
...
Poornima_D
Most Recent 1 week, 5 days ago
Selected Answer: C
Integer can cast to long but not to String
upvoted 1 times
...
vic88
6 months, 1 week ago
can't cast long to String. n2
upvoted 1 times
...
Dibya17
1 year, 2 months ago
Correct answer is C, as we cannot cast from long to string
upvoted 1 times
...
Sezam
1 year, 7 months ago
Selected Answer: C
Answer is C
upvoted 1 times
...
NabilBenAsker
1 year, 9 months ago
Selected Answer: C
Compilation fail cannot cast from Long to String. we have to use String.valueOf(s2+s3) or change the variable s4 to Long
upvoted 1 times
...
Mete5554
2 years, 4 months ago
output = java: incompatible types: long cannot be converted to java.lang.String
upvoted 1 times
...
iSnover
2 years, 5 months ago
Selected Answer: C
The answer is the letter C, string is not primitive type to cast, so it's not a Class Cast exception but compilation failure on line n2.
upvoted 1 times
...
bakhdak
2 years, 9 months ago
Answer is C . It is compile error, due to String is not Primitive .
upvoted 1 times
...
AverageJoe
3 years ago
Answer is E
upvoted 1 times
...
LUISGAR
3 years, 1 month ago
If it does not compiles it cannot throw an Exception
upvoted 1 times
...
SSJ5
4 years ago
Correct Answer is C. It fails to compile at line n2
upvoted 2 times
...
Varsha_vanshi
4 years, 1 month ago
Answer is C
upvoted 1 times
...
hackGh
4 years, 4 months ago
c compile error
upvoted 1 times
...
Gyzmou
4 years, 8 months ago
C: $javac HelloWorld.java HelloWorld.java:7: error: incompatible types: long cannot be converted to String String s4 = (String) (s3*s2); ^ 1 error public static void main(String []args){ Short s1 = 200; Integer s2 = 400; Long s3 = (long) s1 + s2; String s4 = (String) (s3*s2); System.out.println("sum is "+s4); }
upvoted 5 times
...
testOz
4 years, 9 months ago
the answer is C. it is about casting but it gives alert at the compile time
upvoted 4 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago