This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Source: Get Certified Exam Lab / Practice Exam 1, Q No. 29 Which of the lines cause exception? Answer: None of the line cause exception.
I am able to understand till line 16.
But in line 17, there is a casting done on m with reference variable of type A. My doubt is: When there is no relation between A and Min, how is this reference variable casting working? What are the rules behind this? And beyond line 17 too, I am getting confused
I am having a tough time understanding this. If anyone could explain this concept (casting with respect to interfaces specifically) in a simple way, I would be pleased.
Thanks in advance. [ November 20, 2008: Message edited by: Rekha Srinath ]
Well line 17 works as A and Min have a common sub type B. So the object represented by m might point to an object of class B this is why the assignment worked. Even the cast is not neccesary. If however m points to an object of type other than B, then there will be a ClassCastException at runtime but in the question we are concerned about compilation only. This problem that I posted when I first came to javaranch is also a similar problem but it is related to instanceof... [ November 20, 2008: Message edited by: Ankit Garg ]