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

answer please

 
josephine chen
Ranch Hand
Posts: 216
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
given classes MyBase and MySub such that MySub is a subclass of MyBase, which line(s) if any cause a compiler error? Which line(s) if any cause a ClassCastException...
1. MyBase objBase = new MyBase(); ok
2. MySub objSub = new MySub(); ok
3. objBase = objSub; ok
4. objSub = obj ??? consider obj is a object of class Object
5. objBase = (MyBase)objSub;??
6. objSub = (MySub)objBase;???
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
Only line 4 causes compilation error, the rest of the lines are correct. Explicit cast is needed at line 4.
The line 4 could be modified as
objSub =(MySub) obj ;
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic