Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
RuntimeException
preeti khane
Ranch Hand
Posts: 93
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program? class A {} class B extends A {} class C extends A {} public class Q3ae4 { public static void main(String args[]) { A x = new A(); B y = new B(); C z = new C(); // insert statement here } } 1) x = y; 2) z = x; 3) y = (B) x; 4) z = (C) y; 5) y = (A) y;
answer is 3 only
But I think it should be 3 and 4
Reshma Shanbhag
Ranch Hand
Posts: 208
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Preethi refer this
thread
at the end Dan has given a very good explanation of Casting.
Hope this helps you.
reshma
SCJP 1.4, SCWCD 1.4
preeti khane
Ranch Hand
Posts: 93
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
my mistake
I kept thinking C extends B
But C only extends A then there is no problem
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
On the Same liness... as Bill... yet another one from Khalid
Cast Question
Reference Casting
ClassCastException Doubts
Casting
More...