This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Casting

 
aishwarya mathur
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain me the below code from Khalid's on pgno.268
 
Mark Patrick
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you want to know about it?
 
Ozgur Nickpherly
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think question:
What is the result of code?
arrays are object so they can be cast to super class arrays. But casting to subclass occurs Runtime Exception.

public class Myclass {
public static void main(String args[]) {
A[] arrA;
B[] arrB;
arrA = new A[10];
arrB = new B[10];
arrA = arrB;
arrB = (B[])arrA;
arrA = new A[10]; //arrA has A object array
arrB = (B[]) arrA; //Run time error occurs while casting to subclass
}}
class A{}
class B extends A{}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic